How to remove leading and trailing whitespaces from a string in Swift

1 Answer

0 votes
import Foundation

var s = "         swift python java php c c++    "

print(s.count) // Length before trimming

s = s.trimmingCharacters(in: .whitespaces)

print(s.count) // Length after trimming

print(s) 



/*
run:

40
27
swift python java php c c++

*/

 



answered Jul 26 by avibootz
...