0

I read data from an API and I see this string: text = "\n\Ufeff211419";

How can can process it to have the result: 211419 ? I used trim function of NSString, but it did not work. Thank you very much!

Nekto
  • 17,837
  • 1
  • 55
  • 65
abelhoang
  • 271
  • 4
  • 14
  • 4
    Go read the NSString docs. This would be really simple if you were familiar with the methods in that class. – rdelmar Oct 05 '12 at 02:44
  • Visit link below [remove-all-but-numbers-from-nsstring][1] [1]: http://stackoverflow.com/questions/1129521/remove-all-but-numbers-from-nsstring –  Oct 05 '12 at 05:58
  • NSString shows error because of "\U" in ur string. – Jayaraj Oct 05 '12 at 06:10

2 Answers2

1

try this one,

NSString *strippedString=@"";
    NSString *originalString = @"1This is my string.#/hfg34y387t59hguhfytfrg64r34nfr31234";
    for (int i=0; i<[originalString length]; i++) {
        if (isdigit([originalString characterAtIndex:i])) {
            strippedString=[NSString stringWithFormat:@"%@%c",strippedString,[originalString characterAtIndex:i]];


        }
    }
    NSLog(@"string is%@",strippedString);
Balu
  • 8,470
  • 2
  • 24
  • 41
0

substringFromIndex or substringToIndex would help!

Nekto
  • 17,837
  • 1
  • 55
  • 65
casillas
  • 16,351
  • 19
  • 115
  • 215
  • 1
    Nekto added back tick characters around the method names so that they would be properly highlighted. – vacawama Oct 05 '12 at 02:52