swift的一些基本屬性6 (字串)

2021-07-10 08:57:38 字數 1237 閱讀 6723

-字串

swift

string,是乙個結構體,量級更輕,效率略高,推薦使用

可以支援遍歷

oc      nsstring,是繼承自 nsobject 的物件

/// 遍歷字串

func demo()

}}

/// 字串拼接

func demo2()

/// 長度

func demo3()

/// 子串 - 方便的方法,轉換成 nsstring

func demo5() {

let str = "我們一起去飛"

// 1. 方法1,使用 nsstring

let substr1 = (str as nsstring).substringwithrange(nsmakerange(2, 4))

print(substr1)

2. 方法2,swift的語法

startindex 是字串的起始索引位置 -> 0

endindex 是字串的結束的索引位置 -> count

advancedby 是將索引遞進的函式

n > 0 向右遞進 n 個字元

n < 0 向左遞進 n 個字元

let substr2 = str.substringfromindex(str.startindex.advancedby(2))

print(substr2)

// can not increment endindex,不允許遞增 endindex,會出現越界

let substr3 = str.substringtoindex(str.endindex.advancedby(-2))

print(substr3)

// 從 xcode 7 beta 5 開始就固定了格式了

let startindex = str.startindex //.advancedby(2)

let endindex = str.endindex //.advancedby(-2)

print(startindex)

print(endindex)

// 提示如果 範圍越界,會崩潰

let substr4 = str.substringwithrange(startindex..

SlidingMenu的一些基本屬性

slidingmenu 常用屬性介紹 menu.setmode slidingmenu.left 設定左滑選單 menu.settouchmodeabove slidingmenu.touchmode fullscreen 設定滑動的螢幕範圍,該設定為全屏區域都可以滑動 menu.setshadow...

css的一些基本屬性

css屬性的名稱是不會改變的,能改變的只有屬性的取值。width 寬度 height 高度 color 字型顏色 background color 背景顏色 text align 字型格式 居中,靠左,靠右 line height 字型上下 靠上,靠下,垂直居中 margin 設定所有外邊距屬性。該...

CSS flex 布局 一些基本屬性應用

box orient box pack box align box direction box lines box orient horizontal vertical inline axis block axis 預設值 horizontal 適用於 伸縮盒容器 繼承性 無 動畫性 否 計算值 指...