Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2010, 08:15 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Question NSString ==> remove "carriage return" ?????

How can i remove the carriage return from my NSString???
I tried :
str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
but that didn't remove it
aryaxt is offline   Reply With Quote
Old 06-23-2010, 08:37 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 370
david_david is on a distinguished road
Default

It works fine..
Code:
NSString *test = @"123\n4";
test = [test stringByReplacingOccurrencesOfString:@"\n" withString:@""];
	
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ApplicationName", @"") 
													message:test
												   delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"") otherButtonTitles:NSLocalizedString(@"OK", @""), nil];
	

[alert show];
[alert release];
__________________
lazy blogs
The Lord's holy name be praised.
david_david is offline   Reply With Quote
Old 06-23-2010, 10:12 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

there is no "\n" in my string, but when i use NSLog to see it's data i see that at some points the string skips to a new line
aryaxt is offline   Reply With Quote
Old 06-23-2010, 10:38 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Thats what a "\n" IS.

If you're carriage return is only at the end of the line you can try
Code:
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
smithdale87 is offline   Reply With Quote
Old 06-23-2010, 10:43 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

thanks for the reply, and no the carriage return is all over the place. is there a way to remove them all.
Is replacing "\n" with "" suppose to work?
aryaxt is offline   Reply With Quote
Old 06-23-2010, 10:47 AM   #6 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Quote:
Originally Posted by aryaxt View Post
Is replacing "\n" with "" suppose to work?
Yes.

See david_david's post.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-23-2010, 10:52 AM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

The thing about carriage returns, some OS's put in more than just "\n".

Try the following:
Code:
NSArray* newLineChars = [NSArray arrayWithObjects:@"\u000A", @"\u000B",@"\u000C",@"\u000D",@"\u0085",nil];

for( NSString* nl in newLineChars )
    str = [str stringByReplacingOccurrencesOfString: nl withString:@""];
smithdale87 is offline   Reply With Quote
Old 06-23-2010, 10:58 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

I get an error on this, it won't build
'\u000A' is not a valid universal character
'\u000B' is not a valid universal character
'\u000D' is not a valid universal character
'\u0085' is not a valid universal character
aryaxt is offline   Reply With Quote
Old 06-23-2010, 11:02 AM   #9 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Sorry, wasntpositive how to put those chars, and since I'm not near a mac, I can't verify. One moment, I'm sure some googling can figure this out..
smithdale87 is offline   Reply With Quote
Old 06-23-2010, 11:06 AM   #10 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

This may be usefu, try this: ( Again not near my mac, so you get to be the guinea pig )
Code:
NSArray* newLineChars = [NSArray arrayWithObjects:@"\\u000A", @"\\u000B",@"\\u000C",@"\\u000D",@"\\u0085",nil];
smithdale87 is offline   Reply With Quote
Old 06-23-2010, 11:30 AM   #11 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

thanks a lot, I'll give it a try
aryaxt is offline   Reply With Quote
Old 02-15-2011, 04:25 AM   #12 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 5
fbartolom is on a distinguished road
Default

Quote:
Originally Posted by aryaxt View Post
thanks a lot, I'll give it a try
I would like to also display on the web a text composed on the iPhone.
The problem is that when I display it on a web text area all newlines are turned into %10.
Conversely when I write the text on the web it get displayed correctly on the iPhone.
The question is what operation should I make to the NSString before submitting it to the sql server so to replace the %10's with more portable characters.
fbartolom is offline   Reply With Quote
Old 02-15-2011, 04:34 AM   #13 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 13
IceMan85 is on a distinguished road
Default

Quote:
Originally Posted by fbartolom View Post
I would like to also display on the web a text composed on the iPhone.
The problem is that when I display it on a web text area all newlines are turned into %10.
Conversely when I write the text on the web it get displayed correctly on the iPhone.
The question is what operation should I make to the NSString before submitting it to the sql server so to replace the %10's with more portable characters.
Hi, can you post some examples of what is happening please ?
web -> iPhone and iPhone -> web

Cheers
IceMan85 is offline   Reply With Quote
Old 02-15-2011, 11:59 AM   #14 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Quote:
Originally Posted by fbartolom View Post
I would like to also display on the web a text composed on the iPhone.
The problem is that when I display it on a web text area all newlines are turned into %10.
Conversely when I write the text on the web it get displayed correctly on the iPhone.
The question is what operation should I make to the NSString before submitting it to the sql server so to replace the %10's with more portable characters.
If you have problem/question don't just post it in any random thread. Create a new thread for it. If some other thread is relevant, link to it.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
carriage return, enter, nsstring, return, string

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 335
8 members and 327 guests
anothermine, Chickenrig, Domele, givensur, heshiming, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0