-2

Possible Duplicate:
Replacing one character in a string in Objective-C
Remove all whitespace from NSString

@"this string contains blank spaces".

How can we convert this string into @"thisstringcontainsblankspaces".

I mean how can we trim all the blank spaces and new line charecters in a string. I have already tried NSCharecterSet by using whitespaceCharacterSet. But this only removes the spaces at the ends of the string and not in between....

Any ideas??

Community
  • 1
  • 1
A for Alpha
  • 2,904
  • 8
  • 42
  • 76

3 Answers3

5

Use this code to remove the white space:

NSString *str    =  @"this string contains blank spaces";
NSString *newStr = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
3
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
whiteagle
  • 1,158
  • 10
  • 12
0

Use following code:

[YourString stringByReplacingOccurrencesOfString:@" " withString:@""];

You can pass any character or word which you want to replace at

stringByReplacingOccurrencesOfString:@" "

and replacing word/string/character:

withString:@" "

Enjoy coding.

Hemang
  • 1,224
  • 9
  • 15