Swift 练笔 —— 逆转字符串
作者:
码上说 | 来源:发表于
2017-01-16 01:09 被阅读23次/***********************************************************
@Execise:
A function used to reverse string
字符串逆转函数
@notice:
1. type 'String' does not comform to protocol 'Sequence'
字符串类型不符合元组协议
2. 'reverse()' has been renamed to 'reversed()'
reverse() 方法已经被重命名为 reversed()
***********************************************************/
func reverseString(_ string: String) -> String {
return String(string.characters.reversed())
}
// example
let original = "123abc❤我"
print("original string : \(original)") //original string : 123abc❤我
print("reversed string : " + reverseString(original)) //reversed string : 我❤cba321
本文标题:Swift 练笔 —— 逆转字符串
本文链接:https://www.haomeiwen.com/subject/vbmubttx.html
网友评论