开发者

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


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.


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]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜