abelhoang
abelhoang

Reputation: 311

How to process this NSString?

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!

Upvotes: 0

Views: 140

Answers (2)

Balu
Balu

Reputation: 8460

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);

Upvotes: 1

casillas
casillas

Reputation: 16803

substringFromIndex or substringToIndex would help!

Upvotes: 0

Related Questions