Get nth character of a string in Swift programming language
Asked 07 September, 2021
Viewed 1.6K times
  • 58
Votes

How can I get the nth character of a string? I tried bracket([]) accessor with no luck.

var string = "Hello, world!"

var firstChar = string[0] // Throws error

  

ERROR: 'subscript' is unavailable: cannot subscript String with an Int, see the documentation comment for discussion

30 Answer