實例方法
joined(separator:)
通過連接序列的元素返回一個新字符串,在每個元素之間添加給定的分隔符。
聲明
func joined(separator: String = "") -> String
當
Element
為 String
時可用。返回值
單個連接的字符串。
參數
separator
要在此序列中的每個元素之間插入的字符串。默認分隔符是一個空字符串。
詳述
以下示例顯示了如何將字符串數組連接到一個以逗號分隔的字符串:
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let list = cast.joined(separator: ", ")
print(list)
// Prints "Vivien, Marlon, Kim, Karl"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift BidirectionalCollection subscript(_:)用法及代碼示例
- Swift BidirectionalCollection last(where:)用法及代碼示例
- Swift BidirectionalCollection lastIndex(where:)用法及代碼示例
- Swift BidirectionalCollection lastIndex(of:)用法及代碼示例
- Swift BidirectionalCollection indices用法及代碼示例
- Swift BidirectionalCollection index(_:offsetBy:)用法及代碼示例
- Swift BidirectionalCollection reversed()用法及代碼示例
- Swift BidirectionalCollection index(_:offsetBy:limitedBy:)用法及代碼示例
- Swift BidirectionalCollection dropLast(_:)用法及代碼示例
- Swift BidirectionalCollection suffix(_:)用法及代碼示例
- Swift BidirectionalCollection last用法及代碼示例
- Swift BinaryInteger quotientAndRemainder(dividingBy:)用法及代碼示例
- Swift BinaryInteger trailingZeroBitCount用法及代碼示例
- Swift BinaryInteger init(clamping:)用法及代碼示例
- Swift BinaryInteger <<=(_:_:)用法及代碼示例
- Swift BinaryInteger !=(_:_:)用法及代碼示例
- Swift BinaryInteger /(_:_:)用法及代碼示例
- Swift BinaryInteger init(truncatingIfNeeded:)用法及代碼示例
- Swift BinaryInteger ==(_:_:)用法及代碼示例
- Swift BinaryFloatingPoint binade用法及代碼示例
- Swift BinaryInteger init(_:)用法及代碼示例
- Swift BinaryInteger %=(_:_:)用法及代碼示例
- Swift BinaryFloatingPoint random(in:using:)用法及代碼示例
- Swift BinaryInteger &=(_:_:)用法及代碼示例
- Swift BinaryInteger |(_:_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 BidirectionalCollection joined(separator:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。