views:

1130

answers:

3

I Have String like this

Hello

World

of

Twitter

Lets See this

>

I want to transform it to:: Hello World of Twitter Lets See this >

How should i perform such activity.on iPhone

+4  A: 

Split the string into components and join them by space:

NSString *newString = [[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
m5h
I have already tried this but sorry no luck man
y ramesh rao
-stringByTrimmingCharactersInSet will remove characters only from the beginning and the end of the string
Vladimir
okay thats the point i have new line characters all over the place
y ramesh rao
Ah my bad, updated the example to split the string and join it by putting a space in instead of the newline characters.
m5h
Wow, missed this method in NSArray
Vladimir
Yeah, it's hard to spot as it's on NSArray. Double checked now and noticed that it's actually linked from the API docs to componentsSeparatedByString on NSString.
m5h
+1  A: 

I'm using

[...]
myString = [myString stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
[...]

/Paul

Paul Peelen
+2  A: 


Splitting the string into components and rejoining them is a very long-winded way to do this. I too use the same method Paul mentioned. You can replace any string occurrences. Further to what Paul said you can completely delete characters like this:

myString = [myString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
imnk