How to extract strings one by one in go language
In this article, the editor introduces in detail "how to extract strings one by one in go language". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to extract strings in go language one by one" can help you solve your doubts.
Go language traverses strings-- gets each string element
Traverse every ASCII character
Traversing ASCII characters traverses using for's numeric loop, directly fetching the subscript of each string to get ASCII characters, as shown in the following example.
Package mainimport "fmt" func main () {theme: = "hello" for I: = 0; I < len (theme); iTunes + {fmt.Printf ("ascii:% c% d\ n", theme [I], theme [I])}}
The program output is as follows:
Ascii: h 104ascii: e 101ascii: l 108ascii: l 108ascii: O 111ascii: 32ascii: P 112ascii: h 104ascii: P 112ascii: ä 228ascii:, 184ascii: 173ascii: æ 230ascii: 150ascii: 135ascii: ç 231ascii: 189ascii: â 145
The Chinese characters obtained in this mode are "miserable". Because Unicode is not used, Chinese characters are displayed as garbled.
Traversing strings by Unicode character
The same content:
Package mainimport "fmt" func main () {theme: = "hello" for _, s: = range theme {fmt.Printf ("Unicode:% c% d\ n", s, s)}}
The program output is as follows:
Unicode: h 104Unicode: e 101Unicode: l 108Unicode: l 108Unicode: O 111Unicode: 32Unicode: P 112Unicode: h 104Unicode: P 112Unicode: in 20013Unicode: text 25991Unicode: net 32593, this article "how to extract strings one by one in go language" has been introduced. If you want to master the knowledge of this article, you need to practice and use it before you can understand it. If you want to know more about related articles, please pay attention to the industry information channel.