Find number of spaces in a string in Swift

后端 未结 3 1035
抹茶落季
抹茶落季 2020-12-11 18:41

What method do I call to find the number of spaces in a string in Swift? I want to loop through that number, something like this:

@IBOutlet weak var stack: U         


        
3条回答
  •  無奈伤痛
    2020-12-11 19:22

    let title = "A sample string to test with."
    let count = title.componentsSeparatedByString(" ").count - 1
    print(count) // 5
    

提交回复
热议问题