0

Why does this work only 4/5 cases

I have a code for no numerals and it works only 4 out of 5 cases string = gets string.gsub!(/1/, "one") string.gsub!(/0/, "zero") string.gsub!(/2/, "two") string.gsub!(/3/, "three") string.gsub!(/4/, "four") string.gsub!(/5/, "five") string.gsub!(/6/, "six") string.gsub!(/7/, "seven") string.gsub!(/8/, "eight") string.gsub!(/9/, "nine") string.gsub!(/10/, "ten") puts string

17th Feb 2021, 3:59 AM
i changed my name cuz it was cringe
i changed my name cuz it was cringe - avatar
2 Answers
+ 2
10 will not be ten, but rather one zero because you put string.gsub!(/1/, "one") and string.gsub!(/0/, "zero") before string.gsub!(/10/, "ten"). They will be found first and modify the string before 10 can get matched. Put string.gsub!(/10/, "ten") before string.gsub!(/1/, "one")
17th Feb 2021, 4:30 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 1
Ohhh i get it thank you
17th Feb 2021, 4:31 AM
i changed my name cuz it was cringe
i changed my name cuz it was cringe - avatar