//
Main.m
// string comparison judgment
//
Created by admin on 15/8/13.
Copyright (c) years admin. All rights reserved.
//
#import <Foundation/Foundation.h>
int Main (int argc,const Char * argv[]) {
@autoreleasepool {
//1. Determines whether a string is empty
nsstring *str = @ "";
if (str = = Nil | | str.length = =0) {
NSLog (@ " string is empty ");
}
//2. Determines whether a string starts with the specified content
nsstring *str1 = @ "www.baidu.com";
BOOL isperfix = [str1 hasprefix:@ "RWW"]; //Perfix prefix
if (Isperfix) {
NSLog (@ " starts with ww ");
}Else
{
NSLog (@ " start error ");
}
NSLog (@ "Hasperfix%@", Isperfix? @ "YES": @ "NO"); optimization of the above judgment
//3. Determines whether a string ends with the specified content
In the development of commonly used in judging file formats such as:. txt. AVI,.RMVB mkv Doc mp3,mp4 PDF
BOOL issuffix = [str1 hassuffix:@ "com"]; //suffix suffix
NSLog(@ "Hassuffix%@", Issuffix? @ "YES" : @ "NO");
/ * 4. Determine if two strings are equal
Note:
> uses = = To determine two strings, in fact, to determine whether the address of two strings is equal
> If the addresses are equal, then the strings are equal
> However, in the actual development, remember not to use = = To determine the two strings of equal
> to determine if two strings are equal , you must use the method that NSString provides to us
Isequaltostring
*/
nsstring *str2 = @ "ABCDEFGH";
nsstring *STR3 = @ "abcdeeee";
BOOL isequal = [str2 isequaltostring: STR3];
NSLog (@ "IsEqual%@", isequal?) @ "YES" : @ "NO");
/*
5. Isequaltostring 's enhanced version compare
> Compare compares ASCII values
> The return value is an enumeration
*/
nscomparisonresult result = [str2 compare: STR3];
Switch (Result) {
casensorderedascending:
NSLog(@ "nsorderedascending");
break;
Case nsorderedsame:
NSLog (@ "Nsorderedsame");
break;
casensordereddescending:
NSLog(@ "nsordereddescending");
break;
default:
break;
}
}
return 0;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Small white Learning Development (IOS) OC_ string comparison judgment (2015-08-12)