hi all iphone users... hey i have an problem that i cant remove whitespace character or /n/t in string and it retrieve from xml file. like my XMl as
<?xml version="1.0" encoding="UTF-8"?>
<alluser>
<user>
<username>User</username>
<password>Pass</password>
</user>
<user>
<username>Sunny</usern开发者_如何转开发ame>
<password>Dave</password>
</user>
</alluser>
it is of when i use whole data in single line. so please help me for this thing....
Remember that \n
is a newline character. If you would like to extract separate lines based on \n
you can try the following:
-(NSArray *)breakStringByNewlines:(NSString *)line {
NSArray *myArray = [line componentsSeparatedByString:@"\n"];
return myArray;
} // breakStringByNewlines
myArray will have elements that are the lines which were separated by \n
And to remove \t
which is just whitespace, from a line, you could use this:
-(NSString *)removeWhiteSpaceFromLine:(NSString *)line {
NSString *newline = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
return newline;
} // removeWhiteSpaceFromLine
Hope that helps.
Try following code:
NSString *data= [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
精彩评论