FINAL OBJECTIVE: Turn integers into written long hand.
I have seen some discussions on this which are over my head. I have come across functions which happily break up a string and print out the characters but capturing them in an array seems impossible.
It seems individual characters can be accessed by subscript but they can't be operated on.
The following will print out 1,2,9,.,5,0 if I remove the commenting out but when I run through the if loop I get written number strings but in the wrong sequence.
let sentence = "129.50"
for (character) in sentence {
// print(character)
if character == "0" {
print("zero")
}
if character == "1" {
print("one")
}
if character == "2" {
print("two")
}
etc etc
I have also tried to access the indexing function via a function and although it prints out in full every time it always crashes at the end.
func speakNum(_ num:Int) {
let strgNum = String(num)
for t in 0...strgNum.count {
let index = strgNum.index(strgNum.startIndex, offsetBy:t)
//strgnum.index(strgNum.startIndex, offsetBy:t)
print(String(strgNum[index]))
}
}
Any help appreciated.
for t in 0..<strgNum.count, notfor t in 0...strgNum.count.switchinstead of all of thoseifstatements. Or at least useif elsesince only one can be true in a given iteration.