Skip to content

Instantly share code, notes, and snippets.

@hhhello0507
Created March 25, 2025 12:46
Show Gist options
  • Save hhhello0507/2dd6e93d6e2e6f11f198e06a5b6d932d to your computer and use it in GitHub Desktop.
Save hhhello0507/2dd6e93d6e2e6f11f198e06a5b6d932d to your computer and use it in GitHub Desktop.
import Foundation
public extension StringProtocol {
subscript(offset: Int) -> Character { self[index(startIndex, offsetBy: offset)] }
subscript (bounds: CountableRange<Int>) -> String {
let start = index(startIndex, offsetBy: bounds.lowerBound)
let end = index(startIndex, offsetBy: bounds.upperBound)
return String(self[start..<end])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment