tags:

views:

1238

answers:

3

I am parsing a tab seperated list using a NSScanner based upon each line and the tabs. However for some reason the last field in the array (parsed from each row) contains a \r character.

How can I strip this from the NSString that represents the line (or the field)

A: 

Try using the +[NSCharacterSet newlineCharacterSet] method with NSScanner in your various scanning method calls.

robottobor
A: 

If the \r character is at the end (probably because the file being parsed is CRLF), you can just do something like [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]. (You might want to use an explicitly created '\r' character set instead if you don't want to strip whitespace as well.)

Chuck
I ended up just using a substring, but this is probably the most appropriate answer
tigermain
A: 

Just FYI, The \r is part of the line ending for a file created in a windows environment.

Matthew Brubaker