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 introduces the knowledge of "how to use the strings function commonly used in Go". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Strings functions commonly used in Golang
Function introduction len (str) 1. Count the string length by byte len (str)
two。 String traversal, processing Chinese RRV = [] rune (str)
3. String to integer n, err: = strconv.Atoi ("12")
4. Integer to string str = strconv.Itoa (12345)
5. String to [] byte var bytes = [] byte ("hello go")
6. [] byte into the string str = string ([] byte {97,98,99})
7. 10 to 2, 8, 16: str = strconv.FormatInt (123,2) / / 2-> 8,16
8. Find whether the substring is strings.Contains ("seafood", "foo") / / true in the specified string
9. Count the number of specified substrings strings.Count ("ceheese", "e") / / 4 in a string
10. Case-insensitive string comparison (= = is case-sensitive) fmt.Println (strings.EqualFold ("abc", "Abc")) / / true
11. Returns the index value of the first occurrence of the substring in the string, if it does not return-1 strings.Index ("NLT_abc", "abc") / / 4
twelve。 Returns the index of the last occurrence of the substring in the string, if no-1 strings.LastIndex ("go golang", "go") is returned
13. Replace the specified substring with another substring strings.Replace ("go go hello", "go", "go language", n). N can specify how many you want to replace, if nymph 1 means to replace all.
14. Splits a string into a string array strings.Split ("hello,wrold,ok", ",") in order to split the identity according to a specified character.
15. Uppercase and lowercase conversion of string letters: strings.ToLower ("Go") / / go strings.ToUpper ("Go") / / GO
16. Remove the spaces on the left and right sides of the string: strings.TrimSpace ("tn a lone gopher ntrn")
17. Remove the characters specified on the left and right sides of the string: strings.Trim ("! hello!", "!")
18. Remove the specified character on the left side of the string: strings.TrimLeft ("! hello!", "!")
19. Remove the specified character on the right side of the string: strings.TrimRight ("! hello!", "!")
20. Determines whether the string begins with the specified string: strings.HasPrefix ("ftp://192.168.10.1"," ftp ")
21. Determine whether a string ends with a specified string: strings.HasSuffix ("NLT_abc.jpg", "abc") / / false "how to use strings functions commonly used in Go" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.