How can I get the number of characters of a string in Go?
For example, if I have a string "hello"
the method should return 5
. I saw that len(str)
returns the number of bytes and not the number of characters so len("£")
returns 2 instead of 1 because £ is encoded with two bytes in UTF-8.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…