In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what are the commonly used string processing methods in Go language, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
The code is as follows:
Package mainimport ("fmt"strings" / / "unicode/utf8") func main () {fmt.Println ("find whether the substring is in the specified string") fmt.Println ("usage of Contains function") fmt.Println (strings.Contains ("seafood", "foo")) / / true fmt.Println (strings.Contains ("seafood", "bar")) / / false fmt.Println (strings.Contains ("seafood") ")) / / true fmt.Println (strings.Contains (", ") / / true pay special attention to fmt.Println (strings.Contains (" I am Chinese "," I ") / / true fmt.Println (") fmt.Println ("usage of ContainsAny function") fmt.Println (strings.ContainsAny ("team") "I")) / / false fmt.Println (strings.ContainsAny ("failure", "u & I")) / / true fmt.Println (strings.ContainsAny ("foo", ")) / / false fmt.Println (strings.ContainsAny (", ") / / false fmt.Println (") fmt.Println ("usage of the ContainsRune function") fmt.Println (strings.ContainsRune ("I am China") 'I') / / true pay attention to the second parameter Use the characters fmt.Println (") fmt.Println (" usage of Count function ") fmt.Println (strings.Count (" cheese "," e ")) / / 3 fmt.Println (strings.Count (" five ",")) / / before & after each rune result: 5, and the source code implements fmt.Println (") fmt.Println (" usage of EqualFold function ") fmt.Println (strings.EqualFold (" Go ") "go")) / / ignore case fmt.Println (") fmt.Println (" usage of Fields function ") fmt.Println (" Fields are:% Q ", strings.Fields (" foo bar baz ")) / / [" foo "" bar "" baz "] returns a list / / equivalent to using a function as an argument Anonymous functions for _, record: = range [] string {"aaa*1892*122", "aaa\ taa\ t", "124 | 939 | 22"} {fmt.Println (strings.FieldsFunc (record) are supported Func (ch rune) bool {switch {case ch > '5examples: return true} return false})} fmt.Println ("") fmt.Println ("usage of HasPrefix function") fmt.Println (strings.HasPrefix ("NLT_abc") "NLT")) / / prefix is fmt.Println (") fmt.Println (" usage of HasSuffix function ") fmt.Println (strings.HasSuffix (" NLT_abc "," abc ")) / / suffix is fmt.Println (") fmt.Println (" usage of Index function ") fmt.Println (strings.Index (" NLT_abc ") which begins with NLT. ("abc")) / / returns the position of the first matching character Here is 4 fmt.Println (strings.Index ("NLT_abc", "aaa")) / / return 1 fmt.Println in existence (strings.Index ("I am Chinese", "medium") / / return 6 fmt.Println ("") fmt.Println ("usage of IndexAny function") fmt.Println (strings.IndexAny ("I am Chinese") in existence Return 6 fmt.Println (strings.IndexAny ("I am Chinese", "and")) / / return-1 fmt.Println (") fmt.Println (" usage of Index function ") fmt.Println (strings.IndexRune (" NLT_abc ",'b')) / / return the position of the first matching character in existence Here is 4 fmt.Println (strings.IndexRune ("NLT_abc",'s')) / / return-1 fmt.Println in existence (strings.IndexRune ("I am Chinese", 'medium')) / / return 6 fmt.Println (") fmt.Println (" usage of Join function ") s: = [] string {" foo "," bar "," baz "} fmt.Println (strings.Join (s,) ")) / / return string: foo, bar, baz fmt.Println (") fmt.Println ("LastIndex function") fmt.Println (strings.LastIndex ("go gopher", "go")) / / 3 fmt.Println (") fmt.Println (" LastIndexAny function ") fmt.Println (strings.LastIndexAny (" go gopher "," go ")) / / 4 fmt.Println (strings.LastIndexAny (" I am Chinese ") "medium") / / 6 fmt.Println (") fmt.Println (" usage of Map function ") rot13: = func (r rune) rune {switch {case r > ='A'& & r ='a'& & r
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.