Strings

  • Indexing a string gives us the UTF-8 representation of each character
  • Underlying elements in a string is an array of bytes
    • Which is always why the length of a string is the number of bytes, not the number of characters

Solved with runes

  • We can cast the string into an array of runes
  • Runes are an alias for int32

String concatenation

  • Strings are immutable
  • We can create a string using var strSlice = []string{"H", "i"}
  • O(n^2) operation since we are creating a new string every time we concatenate 2 strings
    • This is solved using StringBuilding from the strings package from Go
    • type: strings.Builder
    • Methods:
      • .WriteString(“a”) appends a
      • .String() create the new string