实例属性
utf8CString
字符串的连续存储的以 null 结尾的 UTF-8 表示形式。
声明
var utf8CString: ContiguousArray<CChar> { get }
详述
要访问底层内存,请在数组上调用withUnsafeBufferPointer
。
let s = "Hello!"
let bytes = s.utf8CString
print(bytes)
// Prints "[72, 101, 108, 108, 111, 33, 0]"
bytes.withUnsafeBufferPointer { ptr in
print(strlen(ptr.baseAddress!))
}
// Prints "6"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift String uppercased()用法及代码示例
- Swift String init()用法及代码示例
- Swift String init(_:radix:uppercase:)用法及代码示例
- Swift String init(cString:)用法及代码示例
- Swift String suffix(from:)用法及代码示例
- Swift String removeAll(where:)用法及代码示例
- Swift String ...(_:_:)用法及代码示例
- Swift String last用法及代码示例
- Swift String contains(where:)用法及代码示例
- Swift String prefix(through:)用法及代码示例
- Swift String contains(_:)用法及代码示例
- Swift String firstIndex(where:)用法及代码示例
- Swift String init(reflecting:)用法及代码示例
- Swift String first用法及代码示例
- Swift String lowercased()用法及代码示例
- Swift String dropLast(_:)用法及代码示例
- Swift String first(where:)用法及代码示例
- Swift String removeFirst(_:)用法及代码示例
- Swift String removeFirst()用法及代码示例
- Swift String last(where:)用法及代码示例
- Swift String sorted()用法及代码示例
- Swift String removeSubrange(_:)用法及代码示例
- Swift String decodeCString(_:as:repairingInvalidCodeUnits:)用法及代码示例
- Swift String init(stringLiteral:)用法及代码示例
- Swift String flatMap(_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 String utf8CString。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。