user440096
user440096

Reputation:

White space that I cant seem to trim from the string

I was parsing a webpage but sometimes I copy something that appears to be a blank string. White space basically.

I've tried to trim it using numerous ways but it still appears. The length of the string is 2, so I though it was some control characters.

Is there a way to get the chars to print out so I can actually see what they are?

This is what I am doing

    [mutableString replaceOccurrencesOfString:@" " withString:@"" 
options:NSCaseInsensitiveSearch range:(NSRange){0,[mutableString length]}];
    [mutableString replaceOccurrencesOfString:@" " withString:@"" 
options:NSCaseInsensitiveSearch range:(NSRange){0,[mutableString length]}];
    [mutableString stringByTrimmingCharactersInSet:[NSCharacterSet 
newlineCharacterSet]];
    [mutableString stringByTrimmingCharactersInSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet]];
    [mutableString stringByTrimmingCharactersInSet:[NSCharacterSet 
controlCharacterSet]];
    [mutableString stringByTrimmingCharactersInSet:[NSCharacterSet 
nonBaseCharacterSet]];
    NSLog(@" goal scorer %@",mutableString );

I'v tried pretty much everything that I can think of to remove those to invisible characters.

Many Thanks -Code

Upvotes: 0

Views: 401

Answers (2)

jowie
jowie

Reputation: 8068

I can't tell you how to find out what the characters are, but hopefully this will get rid of the characters in the full string (it worked for me anyway). Firstly download RegexKitLite:

http://regexkit.sourceforge.net/RegexKitLite/

Then try:

string = [string stringByReplacingOccurrencesOfRegex:@"[\n\t\r ]+" withString:@" "];

And see if that trims them out.

Upvotes: 1

Jeethu
Jeethu

Reputation: 429

You can try something like the following to print the hexadecimal representation of the characters in your string.

for(NSUInteger i=0,i_l=[str length];i<i_l;i++) {
    NSLog("Character at index: %d -> 0x%X",i,[str characterAtIndex:i]);
}

Upvotes: 0

Related Questions