Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension String {
- func index(at position: Int, from start: Index? = nil) -> Index? {
- let startingIndex = start ?? startIndex
- return index(startingIndex, offsetBy: position, limitedBy: endIndex)
- }
- func character(at position: Int) -> Character? {
- guard position >= 0, let indexPosition = index(at: position) else {
- return nil
- }
- return self[indexPosition]
- }
- }
- if let character = str.character(at: 3) {
- print("I found \(character)") // Нашел 1
- }
- if let character = str.character(at: 31) {
- print("I found \(character)") //Не найдет так как число слишком большое
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement