0

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</username>
       <password>Dave</password>
   </user>  
</alluser>

it is of when i use whole data in single line. so please help me for this thing....

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Sam007
  • 1,385
  • 3
  • 17
  • 32

2 Answers2

2

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.

aqua
  • 3,269
  • 28
  • 41
1

Try following code:

NSString *data= [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Vlad Z.
  • 3,401
  • 3
  • 32
  • 60
Suresh D
  • 4,303
  • 2
  • 29
  • 51