PJR-NSString-Category NSString 的分类开源项目

我要开发同款
匿名用户2014年06月07日
35阅读
所属分类Objective-C、iOS代码库、其他(Others)
授权协议BSD

作品详情

 PJR-NSString-Category是NSString的分类,可以执行很多字符串操作,包括:

Stringvalidation.

Emailvalidation.

Phonevalidation.

URLvalidation.

Addorremovesubstring.

GetSubstring.

GetApplicationversion.

GetApplicationName.

GenerateArrayfromstring.

GetStringfromArray.

GetNumberofwordsinString.

Checkifmystringcontainsonlyletters,onlynumbersorboth.

ConvertNSDatafromNSString.

示例代码:

//Examples of NSString CategoryNSString *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([@"https://www.google.com" isValidUrl]){    NSLog(@"It is valid URL");}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论