Skip to content

Instantly share code, notes, and snippets.

@imjhk03
Last active September 12, 2024 09:02
Show Gist options
  • Select an option

  • Save imjhk03/889b6cd11746dc699a405851a7dd7e4c to your computer and use it in GitHub Desktop.

Select an option

Save imjhk03/889b6cd11746dc699a405851a7dd7e4c to your computer and use it in GitHub Desktop.
Swift String Cheat Sheet
import Foundation
/// Find specific character in String using String.Index (Unicode-compliant way)
/// Usage:
/// let word = "Banana"
/// let fifthCharacter = word[4]
/// print("The 5th character is: \(fifthCharacter)") // Prints: The 5th character is: n
extension StringProtocol {
subscript(offset: Int) -> Character {
self[index(startIndex, offsetBy: offset)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment