[英]String format compare in objective c
hello all i have one NSString
in this format +1-123-123-1234
(phone number US base style) , my question is How can we compare that my string is formted in +1-123-123-1234
format . 你好,我有一个这种格式的
NSString
+1-123-123-1234
(电话号码美国基本风格),我的问题是我们如何比较我的字符串是+1-123-123-1234
格式。
on the basic of String compare formatted i have to done another task ..so any one have any idea regarding same please help me . 在基本的字符串比较格式化我必须做另一个任务..所以任何人有任何想法相同请帮助我。
You can use a NSRegularExpression
to test if your string is of a certain format. 您可以使用
NSRegularExpression
来测试您的字符串是否是某种格式。
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^\\+\\d-\\d{3}-\\d{3}-\\d{4}$"
options:NSRegularExpressionCaseInsensitive
error:nil];
int num = [regex numberOfMatchesInString:phoneNumberHere
options:0
range:NSMakeRange(0, [phoneNUmberHere length])];
if (num == 1) {
// match!
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.