如果文本存在于标签中,则在Xcode中 [英] If text exists in label, in Xcode
问题描述
好的,所以我想看看用户是否在其他单词中插入了一个单词,例如我希望用户打个招呼,但不仅仅是单词hi!例如:
Ok so I wanna see if the user has in putted a single word among other words like for example I want the user to say but not only the word hi! For example like this :
每个人都是XCoder,比如hi class。我想要一个if命令,它将扫描单词hi并删除它,如果它在那里,如果它不对文本做任何事情。
Everybody this is XCoder, say hi class. I want an if command that will scan for the word hi and delete it if it is there and if it is not do nothing to the text.
摘要:扫描特定文本,如果存在子串。或者删除,我很可能期望或期望一个(if)语句比其他任何东西更重要,因为这是一个静态标签,(改变)。
Summary : Scan for particular text, if exists substring it. or remove, I would most likely expecting or expecting a (if) statement more than anything else cause this is a static label, (changing).
推荐答案
从其他帖子引用..
关键是注意到rangeOfString:返回一个NSRange结构,文档说如果haystack不包含结构,它返回结构{NSNotFound,0} 针。
Referred from other post.. The key is noticing that rangeOfString: returns an NSRange struct, and the documentation says that it returns the struct {NSNotFound, 0} if the "haystack" does not contain the "needle".
NSString *myString = @"Hi I am asking for help.";
if ([string rangeOfString:@"Hi"].location == NSNotFound) {
NSLog(@"%@",myString);
} else {
NSString *updated = [myString stringByReplacingOccurrencesOfString:@" am" withString:@""];
NSLog(@"%@",updated);
}
这篇关于如果文本存在于标签中,则在Xcode中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!