//原始資料
let sample_str = "0123456789"
print(sample_str) //....0123456789
//String 取得前5個字串
let sample_sring_5 = sample_str[..<sample_str.index(sample_str.startIndex, offsetBy: 5)]
print(sample_sring_5) //....01234
//String 轉 Array
var sample_str_array = Array(sample_str)
print(sample_str_array) //....["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
//Array 取得前5筆陣列值
let sample_array_5 = sample_str_array[0...4]
print(sample_array_5) //....["0", "1", "2", "3", "4"]
//Array 轉 String
let sample_array_2_str = String(sample_array_5)
print(sample_array_2_str) //....01234
沒有留言:
張貼留言