Skip to main content
2 of 2
deleted 1 character in body
marc_s
  • 759.9k
  • 186
  • 1.4k
  • 1.5k

Swift 5+

Remove All whitespaces from prefix(start) of the string, you can use similar for suffix/end of the string

 extension String { func deletingPrefix(_ prefix: String) -> String { guard self.hasPrefix(prefix) else { return self } return String(self.dropFirst(prefix.count)) } func removeWhitespacePrefix() -> String { let prefixString = self.prefix(while: { char in return char == " " }) return self.deletingPrefix(String(prefixString)) } } 
UnRewa
  • 2.5k
  • 3
  • 29
  • 33