OC字串其它操作

2021-06-28 19:26:14 字數 433 閱讀 6251

oc字串其它操作

//拼接字串

// 對於不可改變的字串操作都是建立乙個新的字串放到裡面

nsstring *str4 = @"iphone6plus";

nslog(@"str8: %@", str8);

//替換字串

nsstring *str9 = [str8 stringbyreplacingoccurrencesofstring:@"6plus" withstring:@"7s"];

nslog(@"str9: %@", str9);

//字串相等判斷

nsstring *str10 = @"123";

nsstring *str11 = @"123";

if (str10 == str11)  else {

nslog(@"相同

");

OC中字串的簡單操作

import int main int argc,const char argv else 6.字串擷取 6.1 擷取前面部分 nslog str1 substringfromindex 3 6.2 擷取後邊部分 nslog str1 substringtoindex 3 6.3 擷取中間部分 ns...

OC取字串操作的方法

oc取字串操作的方法 求字串長度 nsstring str3 abc nslog length lu str3.length 取字串 nsstring p iphone6plus substringfromindex表示從指定位置開始擷取字串到最後,所擷取位置包含該指定位置。fromindex 從當...

OC之字串及其操作函式

1.普通建立 nsstring str nsstring alloc initwithformat d普通 字元 d 4,5 2.便利構造器 nsstring str2 nsstring stringwithformat 便利構造器 3.字面量形式 語法糖 nsstring str1 我是字面量形式...