亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Objective-C常用代碼

發布時間:2020-08-01 11:38:46 來源:網絡 閱讀:235 作者:againbike1 欄目:開發技術

/*******************************************************************************************
    NSString
    *******************************************************************************************/

//一、NSString    
/*----------------創建字符串的方法----------------*/

//1、創建常量字符串。
NSString*astring = @"This is a String!";

//2、創建空字符串,給予賦值。

NSString*astring =[[NSStringalloc]init];
   astring = @"This is a String!";
[astring release];
NSLog(@"astring:%@",astring);

//3、在以上方法中,提升速度:initWithString方法

NSString*astring =[[NSStringalloc]initWithString:@"This is a String!"];
NSLog(@"astring:%@",astring);
[astring release];

//4、用標準c創建字符串:initWithCString方法

char*Cstring="This is a String!";
NSString*astring =[[NSStringalloc]initWithCString:Cstring];
NSLog(@"astring:%@",astring);
[astring release];

//5、創建格式化字符串:占位符(由一個%加一個字符組成)

int i =1;
int j =2;
NSString*astring =[[NSStringalloc]initWithString:[NSStringstringWithFormat:@"%d.This is %i string!",i,j]];
NSLog(@"astring:%@",astring);
[astring release];

//6、創建臨時字符串

NSString*astring;
   astring =[NSStringstringWithCString:"This is a temporary string"];
NSLog(@"astring:%@",astring);

/*----------------從文件讀取字符串:initWithContentsOfFile方法----------------*/

NSString*path= @"astring.text";
NSString*astring =[[NSStringalloc]initWithContentsOfFile:path];
NSLog(@"astring:%@",astring);
[astring release];

/*----------------寫字符串到文件:writeToFile方法----------------*/

NSString*astring =[[NSStringalloc]initWithString:@"This is a String!"];
NSLog(@"astring:%@",astring);
NSString*path= @"astring.text";
[astring writeToFile:pathatomically:YES];
[astring release];    

/*----------------比較兩個字符串----------------*/

//用C比較:strcmp函數

char string1[]="string!";
char string2[]="string!";
if(strcmp(string1, string2)==0)
{
NSLog(@"1");
}

//isEqualToString方法    
NSString*astring01 = @"This is a String!";
NSString*astring02 = @"This is a String!";
BOOL result =[astring01 isEqualToString:astring02];
NSLog(@"result:%d",result);

//compare方法(comparer返回的三種值)    
NSString*astring01 = @"This is a String!";
NSString*astring02 = @"This is a String!";
BOOL result =[astring01 compare:astring02]== NSOrderedSame;
NSLog(@"result:%d",result);
//NSOrderedSame判斷兩者內容是否相同

NSString*astring01 = @"This is a String!";
NSString*astring02 = @"this is a String!";
BOOL result =[astring01 compare:astring02]== NSOrderedAscending;
NSLog(@"result:%d",result);
//NSOrderedAscending判斷兩對象值的大小(按字母順序進行比較,astring02大于astring01為真)

NSString*astring01 = @"this is a String!";
NSString*astring02 = @"This is a String!";
BOOL result =[astring01 compare:astring02]== NSOrderedDescending;
NSLog(@"result:%d",result);
//NSOrderedDescending判斷兩對象值的大小(按字母順序進行比較,astring02小于astring01為真)

//不考慮大小寫比較字符串1
NSString*astring01 = @"this is a String!";
NSString*astring02 = @"This is a String!";
BOOL result =[astring01 caseInsensitiveCompare:astring02]== NSOrderedSame;
NSLog(@"result:%d",result);
//NSOrderedDescending判斷兩對象值的大小(按字母順序進行比較,astring02小于astring01為真)

//不考慮大小寫比較字符串2
NSString*astring01 = @"this is a String!";
NSString*astring02 = @"This is a String!";
BOOL result =[astring01 compare:astring02
options:NSCaseInsensitiveSearch | NSNumericSearch]== NSOrderedSame;



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

东城区| 江永县| 罗源县| 晋江市| 乐陵市| 武穴市| 丹阳市| 太谷县| 巩义市| 万荣县| 江孜县| 三都| 定边县| 甘泉县| 龙海市| 桃园市| 渝北区| 鲜城| 东乌珠穆沁旗| 麻阳| 慈利县| 澎湖县| 盐山县| 保康县| 罗田县| 商水县| 台前县| 东安县| 通州市| 赤峰市| 航空| 新野县| 宝山区| 古交市| 石棉县| 浦城县| 馆陶县| 中山市| 扶余县| 和平区| 光山县|