var text = "This is a boy"
print(text.uppercased())
print(text.lowercased())
输出结果 :
THIS IS A BOY
this is a boy
字符串前后缀判断
var text = "progectNum"
print(text.hasPrefix("progect")) // 是否有前缀
print(text.hasSuffix("Num")) // 是否有后缀
输出结果 :
true
true
索引输出
var text = "progectNum"
for index in text.indices{
print(text[index])
}
输出结果 :
p
r
o
g
e
c
t
N
u
m
该方法也可以用于数组遍历
var array = [1, 2, 4, 3, 7, 9]
for index in array.indices{
print(array[index])
}
输出结果 :
1
2
4
3
7
9