I want to check if a variable has a number in it, I just want to see if there is one I don’t care if it has any thing else in it like so:
"abc" - false
"!./#()" - false
"!./#()abc" - false
"123" - true
"abc123" - true
"!./#()123" - true
"abc !./#() 123" -true
There are easy ways of doing this if you want to know that is all numbers but not if it just has one. Thanks for your help.
You can use the
strcspnfunction:strcspnreturns the length of the part that does not contain any integers. We compare that with the string length, and if they differ, then there must have been an integer.There is no need to invoke the regular expression engine for this.