Last active
September 12, 2024 09:02
-
-
Save imjhk03/889b6cd11746dc699a405851a7dd7e4c to your computer and use it in GitHub Desktop.
Swift String Cheat Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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