Boolean
  • bool
  • boolean
Strings
  • Conventionally UTF-8
  • Built-in function len returns the number of bytes, not runes in a string
  • Detect length of string
    • Convert to []rune and use len()
    • Use unicode/utf8
  • substring, format: string[startIdx:endIdx], need to be reminded you need cast to rune if string contains 
  • Can use + to a append string. 
  • Use == or > or < to compare string byte by byte (natural lexicographic ordering)
  • string is immutable, so you CAN NOT assign value to a char of a string
  • Natural data type to hold a single rune is int32
  • UTF8
    • UTF8 is a variable-length encoding of unicode code points as byte.
    • High order bits of the first byte of the encoding for a rune indicate how many bytes follow. 
    • You can search for rune by searching for its bytes without worrying about the preceding context
    • Lexicographic order equals to unicode point order. So sort UTF8 works naturally
    • Go files always encoded in UTF8
    • For special character. Use \uhhhh for 16 bits value. Usev\Uhhhhhhhh for 32 bits value
    • Can use ==, <, > ...etc to compare string
  • Count characters
    • utf8.RuneCountInString and utf8.DecodeRuneInString
    • Range byte array


Tags:

Updated: