In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to use the rune type in golang". 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!
Rune types in golang
Rune is equivalent to int32 in golang, but is generally used for character conversion. The len () method in golang mainly calculates the length of the array.
The default storage string in golang is utf8 format, utf8 is variable-length byte storage, English letter is single-byte storage, Chinese is 3-byte storage, so the execution results of-1 and-2 are 16 and 15. There are two ways in golang, utf8.RuneCountInString and [] rune (), to convert utf8 into 4-byte int32 storage, and then calculate the length of the int32 array.
-1 address: = "this is shanghai" fmt.Println ("len (address):", len (address))-2 address: = "this is shanghai" fmt.Println ("len (address):", len (address))-3 addressThree: = "this is in Shanghai" fmt.Println ("len (address):", utf8.RuneCountInString (addressThree)-4 fmt.Println ("len (address):", len ([] rune (addressThree)-5 unicode.Is (unicode.Han) C) / / can judge whether the character is Chinese or not
Result
-1 len (address): 16-2len (address): 15-3len (address): 5-4len (address): 5 "how to use rune types in golang" 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.