「Swift」指定範囲(range)の文字列を取得するサンプル

2021年7月20日

書式
文字列.startIndex
文字列.endIndex
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let str = "this is a test message"
let stIdx = str.index(str.startIndex, offsetBy: 3)
let edIdx = str.index(str.endIndex, offsetBy: -2)
str[stIdx...edIdx]
let str = "this is a test message" let stIdx = str.index(str.startIndex, offsetBy: 3) let edIdx = str.index(str.endIndex, offsetBy: -2) str[stIdx...edIdx]
let str = "this is a test message"
 
let stIdx = str.index(str.startIndex, offsetBy: 3)
let edIdx = str.index(str.endIndex, offsetBy: -2)
 
str[stIdx...edIdx]

 

Swift

Posted by arkgame