Xcode 检查字符串中是否有内容

Xcode 检查字符串中是否有内容,xcode,Xcode,我想检查一下字符串中是否有东西。 是这样的: stringByReplacingOccurrencesOfString:@"h" withString:@"a" 但是我想检查字符串中是否有“h”。考虑一下,如果字符串中存在“h”字符,则该方法返回的NSRange将有效 即 给你: NSString *theString = @"just any string that you want"; NSRange match; match = [theString rangeOfString: @"y

我想检查一下字符串中是否有东西。 是这样的:

stringByReplacingOccurrencesOfString:@"h" withString:@"a"
但是我想检查字符串中是否有“h”。

考虑一下,如果字符串中存在“h”字符,则该方法返回的NSRange将有效

给你:

NSString *theString = @"just any string that you want";
NSRange match;
match = [theString rangeOfString: @"you"];
if (match.location == NSNotFound)
          NSLog (@"Sorry, not found.");
else
          NSLog (@"Match found at index %i", match.location);
享受。

Try
boolhexists=([mystringindexofsubstring:@“h”!=NSNotFound)
NSString *theString = @"just any string that you want";
NSRange match;
match = [theString rangeOfString: @"you"];
if (match.location == NSNotFound)
          NSLog (@"Sorry, not found.");
else
          NSLog (@"Match found at index %i", match.location);