开发者

how to remove remove /n /t from string in iphone

开发者 https://www.devze.com 2023-02-03 21:47 出处:网络
hi all iphone users... hey i have an problem that i cant remove whitespace character or /n/tin string and it retrieve from xml file. like my XMl as

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

精彩评论

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