// // StringExt.swift // NFCPassportReaderApp // // Created by Andy Qua on 30/06/2019. // Copyright © 2019 Andy Qua. All rights reserved. // import Foundation /// Some Utility methods for string - access characters by index extension String { subscript(_ i: Int) -> String { let idx1 = index(startIndex, offsetBy: i) let idx2 = index(idx1, offsetBy: 1) return String(self[idx1..) -> String { let start = index(startIndex, offsetBy: bounds.lowerBound) let end = index(startIndex, offsetBy: bounds.upperBound) return String(self[start..) -> String { let start = index(startIndex, offsetBy: bounds.lowerBound) let end = index(startIndex, offsetBy: bounds.upperBound) return String(self[start...end]) } subscript (bounds: CountablePartialRangeFrom) -> String { let start = index(startIndex, offsetBy: bounds.lowerBound) return String(self[start...]) } func strip() -> String { let trimmed = self.trimmingCharacters(in: .whitespacesAndNewlines) return trimmed } }