PJR-NSString-Category 介绍
PJR-Nsstring-Category 是 Nsstring 的分类,可以执行很多字符串操作,包括:
-
String validation.
-
Email validation.
-
Phone validation.
-
URL validation.
-
Add or remove substring.
-
Get Substring.
-
Get Application version.
-
Get Application Name.
-
Generate Array from string.
-
Get String from Array.
-
Get Number of words in String.
-
Check if my string contains only letters, only numbers or both.
-
Convert NSData from Nsstring.
示例代码:
//Examples of Nsstring Category Nsstring *testStr = @"Hello"; if([testStr isValid]){ NSLog(@"It is a Valid String"); } Nsstring *blankStr = @" "; if([blankStr isBlank]){ NSLog(@"It is a blank String"); } Nsstring *noOfWordsstr = @"Number of Words"; NSLog(@"Number of words are :%d",[noOfWordsstr countNumberOfWords]); if([noOfWordsstr containsstring:@"of"]){ NSLog(@"YES"); } if([noOfWordsstr isBeginsWith:@"N"]){ NSLog(@"YES"); } if([noOfWordsstr isEndssWith:@"s"]){ NSLog(@"YES"); } NSLog(@"string after replace charcter is :%@",[noOfWordsstr replaceCharcter:@"of" withCharcter:@"offfff"]); NSLog(@"Get substring :%@",[noOfWordsstr getSubstringFrom:1 to:6]); NSLog(@"Add string :%@",[noOfWordsstr addString:@" are 3"]); NSLog(@"Removed string :%@",[noOfWordsstr removeSubString:@"of"]); Nsstring *letterStr = @"abcd"; Nsstring *numberStr = @"1234"; Nsstring *letterNuberStr = @"sdf545"; if([letterStr containsOnlyLetters]){ NSLog(@"Contanis only letters"); } if([numberStr containsOnlyNumbers]){ NSLog(@"Contanis only numbers"); } if([letterNuberStr containsOnlyNumbersAndLetters]){ NSLog(@"Contanis letters and numbers"); } NSArray *array = [NSArray arrayWithObjects:letterStr,numberStr,letterNuberStr, nil]; if([numberStr isInThisarray:array]){ NSLog(@"Yes number string is in this array"); } NSLog(@"String from array is :%@",[Nsstring getStringFromArray:array]); NSLog(@"Array from String is :%@",[noOfWordsstr getArray]); NSLog(@"My Application Version number is :%@",[Nsstring getMyApplicationVersion]); NSLog(@"My Application name is :%@",[Nsstring getMyApplicationName]); if([@"pjr@gmail.com" isValidEmail]){ NSLog(@"It is valid Email"); } if(![@"21323gf" isVAlidPhoneNumber]){ NSLog(@"It is not valid Phone number"); } if([@"http://www.google.com" isValidUrl]){ NSLog(@"It is valid URL"); }
PJR-NSString-Category 官网
https://github.com/paritsohraval100/PJR-NSString-Category
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。