string - How do I check to see if a character is a space character in Swift? -
in program i'm writing, need check see if character space (" "). have conditional it's not working. ideas? in advance.
for(var k = indexofcharbeingexamined; k < linebeingexaminedchars.count; k++){ let charbeingexamined = linebeingexaminedchars[linebeingexaminedchars.startindex.advancedby(k)]; //operations if(string(charbeingexamined) == " "){ //more operations } }
the following code works me. note it's easier iterate on characters in string using 'for' (second example below):
var s = "x yz" var = 0; < s.characters.count; i++ { let x = s[s.startindex.advancedby(i)] print(x) print(string(x) == " ") } c in s.characters { print(c) print(string(c) == " ") }
Comments
Post a Comment