I have a string say "Allentown, pa"
How to remove the white space in between ,
and pa
using objective c?
The replaceAll() method of the String class replaces each substring of this string that matches the given regular expression with the given replacement. You can remove white spaces from a string by replacing " " with "".
In Java, we can use regex \\s+ to match whitespace characters, and replaceAll("\\s+", " ") to replace them with a single space.
The trim() function removes whitespace and other predefined characters from both sides of a string.
This will remove all space from myString
.
NSString *newString = [myString stringByReplacingOccurrencesOfString:@" " withString:@""];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With