NSLog NSRange problem
I have a NSSting resultcontent that contains html data which is dynamic and length of html data is always different according to user input.
I could insert my html data in SQLite3 by replacing " from NSString. Now the problem is that SQlite3 doesn't have any inbuilt function to find the position of a particular substring. In SQL you can use CHARINDEX or Patindex for this purpose.
Now I am trying to find the position of this substring "sphinx". I tried NSrange, substringWithRange etc. but I am not getting the exact start and end positions of this substring. How do you show NSRange in console by using NSLog. Here is my code
//find substring "sphinx"
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"sphinx"
options:NSRegularExpressionCaseInsensitive
error:&error];
//Get total length of resultcontent (NSString which contains whole html code)
NSInteger lengthTotal=[resultContent length];
NSLog(@"lengthTotal is %i", lengthTotal);
// Get NSRange
NSRange rangeOfSubstring = [regex rangeOfFirstMatchInString:resultContent
options:0
range:NSMakeRange(0, lengthTotal)];
NSString *substringData = [resultContent substringWithRange:rangeOfSubstring];
if (!NSEqualRanges(rangeOfSubstring, NSMakeRange(NSNotFound, 0)))
{
NSString *substringData = [resultContent substringWithRange:rangeOfSubstring];
NSLog(@"substringData is %@", substringData);
[b] // so far it works fine and shows substringData ="sphinx" in Console
//But folowing line doesn't show start and end position of substringData "sphinx"
NSLog([@"range of substring is =%@",[resultConten开发者_如何转开发t substringWithRange:rangeOfSubstring] ];[/b]
}
How do I find the exact position of a substring from NSString? I also tried %S in NSLog but no results.
I also have the same NSString resultcontent Data in SQLite table (text datatype). How do you find index of a character or position of a substring in Sqlite without Charindex and patindex function. As html code is dynamic and length varies according to the user input so I need to know the index or position of substring after each user input.
精彩评论