Tell me how to cut a certain text from a string? For example: NSString * String1 = @ "12345result = 678910"; , here I need in NSString * String2 = @ "678910";
size after result = - dynamic - can reach from 1 to 40 characters.
Tell me how to cut a certain text from a string? For example: NSString * String1 = @ "12345result = 678910"; , here I need in NSString * String2 = @ "678910";
size after result = - dynamic - can reach from 1 to 40 characters.
A popular question. I will climb too
NSString *res = @"122345result=678910"; NSRange position = [res rangeOfString:@"result="]; if(position.location != NSNotFound) { NSString *newString = [res substringFromIndex:position.location+position.length]; }
used this design:
NSArray *data = [@"abc xyz http://www.abc.com aaa bbb ccc" componentsSeparatedByString:@" "]; for(NSString* str in data) { if([NSURLConnection canHandleRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]]) NSLog(@"%@",[[NSString alloc ] initWithFormat:@"Found a URL: %@",str]); }
In your case, the simplest:
NSString *String1 = @"12345result=678910"; NSString *String2 = [String1 stringByReplacingOccurrencesOfString:@"12345result=" withString:@""];
So it will be a little more universal:
NSString *string1 = @"12345result=678910"; NSArray *components = [string1 componentsSeparatedByString: @"="]; NSString *result = nil; if( components.count == 2 ) result = components[1];
Source: https://ru.stackoverflow.com/questions/544914/
All Articles