print("我爱你".characters.count)
输出为3
1:字符串相等 ==
2:前缀相等 hasPrefix()
3:后缀相等 hasSuffix()
//例子
var strA = "Hello"
var strB = "Hello"
//-----------字符串相等 == -------
if strA == strB{
print("字符串-相等")
}
else{
print("字符串-不相等")
}
//-----------字符串前缀相等 hasPrefix---------
if strA.hasPrefix("H"){
print("字符串前缀-相等")
}
else{
print("字符串前缀-不相等")
}
//-----------字符串后缀相等 hasSuffix---------
if strA.hasSuffix("o"){
print("字符串后缀-相等")
}
else{
print("字符串后缀-不相等")
}
-
看我那么可爱n(≧▽≦)n
- 关注我的微薄 (梁同桌):http://weibo.com/tongrenyinsheng
- 个人网站(同人音声) http://www.tongrenyinsheng.com
- ios 个人写的app (同人音声)ASMR音乐