91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

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

区。| 康马县| 汕头市| 清丰县| 绵阳市| 丹凤县| 德江县| 巴塘县| 呼图壁县| 丰顺县| 微山县| 榆树市| 阿拉善右旗| 麟游县| 宝鸡市| 双鸭山市| 乌拉特后旗| 清远市| 黄大仙区| 黔江区| 石河子市| 营口市| 卓资县| 泗水县| 台江县| 子长县| 荣成市| 齐河县| 嵊州市| 潜山县| 郎溪县| 新巴尔虎左旗| 平潭县| 镶黄旗| 化德县| 新营市| 札达县| 江源县| 宽城| 兴业县| 敦煌市|