Swift字符串遍历

// 统计一段字符串中的非元音字符个数

let useInput = "To write the code for class, you must provide three chunks or secetions of code."

var outputCount = 0

for chares in useInput.characters {

switch chares {

case "a", "e", "i", "o", "u":

// 跳出本次循环 直接回到条件判断语句处

continue

default:

print(chares)

outputCount += 1

}

}

print(String(outputCount))

你可能感兴趣的:(Swift字符串遍历)