Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove whitespace in a string?

I have a string say "Allentown, pa"

How to remove the white space in between , and pa using objective c?

like image 333
Maga Avatar asked Jul 07 '11 09:07

Maga


People also ask

How do you remove white spaces from a string?

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 "".

How do I remove spaces between words in a string?

In Java, we can use regex \\s+ to match whitespace characters, and replaceAll("\\s+", " ") to replace them with a single space.

Which function is used to remove whitespace from the string?

The trim() function removes whitespace and other predefined characters from both sides of a string.


1 Answers

This will remove all space from myString.

NSString *newString = [myString stringByReplacingOccurrencesOfString:@" " withString:@""]; 
like image 162
taskinoor Avatar answered Oct 08 '22 08:10

taskinoor