我們知道在objective-c
中我們通常使用length
來獲取nsstring
型別的字串的長度,**示例如下:
nsstring *title = "title";
nsuinteger length = title.length; //獲取nsstring字串長度
nslog(@"%u",length);
而在swift中,string結構體沒有了這個方法,那怎樣獲取string型別的字串的長度呢?我們可以通過他的擴充套件屬性成員characters
的count
屬性來獲取
let title : string = "title"
let count = title.characters.count //獲取string字串的長度
print(count)
Swift 中如何擷取String
swift 中擷取字串的方式非常麻煩,但是在oc中的字串擷取卻比較便捷,要擷取string 只需要將string 轉化為nsstring 在進行擷取就可以了 示例 如下 let mystr www.520it.com var substr mystr as nsstring substringfro...
Swift中獲取隨機數
在我們日常的開發過程中在很多場景都需要獲取隨機數,包括很多資料型別,整形,長整形等。如果我們需要乙個隨機整數,我們可以使用arc4random系列函式,其實這個函式大家用的很多了吧,比如說我們需要生成乙個指定範圍內的乙個隨機數,我們則需要給他指定乙個上限max,arc4ramdom 返回值型別是ui...
獲取Excel Sheet中資料單元格的結尾位置
在excel vba開發過程中經常會遇到遍歷sheet中的資料,常常我們會使用 for i 1 to maxrow for j 1 to maxcolumn next j next i 其中的maxrow和maxcolumn是sheet中資料所在行數的最大值和列數最大值 也就是結尾位置 使用used...