「Swift」指定endIndeより前の文字列を取得するサンプル

2021年7月20日

書式
offsetBy:数字
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let str = "this is a test message"
// 最後から2番目以前
let res= str.index(str.endIndex, offsetBy: -2)
str[...res]
let str = "this is a test message" // 最後から2番目以前 let res= str.index(str.endIndex, offsetBy: -2) str[...res]
let str = "this is a test message"
 
// 最後から2番目以前
let res= str.index(str.endIndex, offsetBy: -2)
str[...res]

 

Swift

Posted by arkgame