dongliyu3278 2015-01-18 16:29
浏览 22
已采纳

如何将定界字符串解析为子字符串切片?

Given a URL like the following:

http://127.0.0.1:3001/find?fields=hostname,App,Node_type,invalid

I extract fields into a slice like this:

filters := r.URL.Query().Get("fields")
fmt.Println(filters)

Result:

hostname,App,Node_type,invalid

It is received as a string, but I'd prefer to separate the substrings into a sequence.

  • 写回答

2条回答 默认 最新

  • dongwuwan5646 2015-01-18 17:02
    关注

    I think your URL should be

    http://127.0.0.1:3001/find?fields=hostname&fields=App&fields=Node_type&fields=invalid
    

    or if you don't like that, you can parse

    filterSlice:=strings.Split("filters", ",")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?