Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

string index in swift

extension String {
    subscript(_ n: Int) -> Character {
        return self[self.index(self.startIndex, offsetBy: n)]
    }
}

let str = "Hello World"

print(str[0]) // H
print(str[4]) // o
print(str[6]) // w
 
PREVIOUS NEXT
Tagged: #string #index #swift
ADD COMMENT
Topic
Name
2+9 =