包含許多常見的NSString操作:PJR-NSString-Category
通過使用這個NSString Category,您可以執行許多常見的NSString操作。不需要創建任何方法或任何class。import this category in your controller by #import "NSString+PJR.h" and you can perform all NSString operations given in this category like:
//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([@"項目主頁:http://www.baiduhome.net/lib/view/home/1402194980025