Con*_*sed -3 string whitespace count swift
我想知道字符串中前导空格的数量。
说,如果字符串是" Hello world ",结果应该是 2
" Hello world "
谢谢
Swe*_*per 6
一种方法是使用prefix(while:), 并计算你得到了多少个字符:
prefix(while:)
yourString.prefix(while: { $0 == " " }).count
归档时间:
5 年,3 月 前
查看次数:
111 次
最近记录: