Checking each character for a number

前端 未结 6 1389
别跟我提以往
别跟我提以往 2021-01-20 10:12

I am trying to loop through a string and check each character if one of the characters is a number. If it is a number, I want to return it as true. I have a string \"crash\"

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-20 10:27

    Maybe I didn't understand you correctly... but since you're using the same variable "isNumber", and continuing when you get a positive match... the result you'll return will always be of the last character of the String, except when you get a non numeric character, in which case, you exit right away.

    Do you want to check if the whole String is a number? Or if it contains a number?

提交回复
热议问题