Wolfman 0 Posted October 3, 2018 Report Share Posted October 3, 2018 I'm trying to iterate over a string and distinguish between numerals and letters, such as in "abcd123efg" My first attempt was: set(#x,"abcd123efg","Global") add list to list(%chars,$list from text($character list(#x),$new line),"Delete","Global") set(#numbers,0,"Global") set(#letters,0,"Global") with each(%chars,#y) { if($comparison($is number(#y),"= Equals",$true)) { then { increment(#numbers) } else { increment(#letters) } } } however the debugger revealed that #letters was being incremented for every character. Thinking that perhaps I need to convert the string representation to an integer, I wrote a small function in python to do so: set(#x,"abcd123efg","Global") add list to list(%chars,$list from text($character list(#x),$new line),"Delete","Global") set(#numbers,0,"Global") set(#letters,0,"Global") with each(%chars,#y) { set(#y,$ConvertStringToInt(#y),"Global") if($comparison($is number(#y),"= Equals",$true)) { then { increment(#numbers) } else { increment(#letters) } } } define $ConvertStringToInt(#string_char) { set(#char_to_return,$run python with result("def convertStringToInt(string): if string.isdigit(): return int(string) else: return string convertStringToInt(\"{#string_char}\")"),"Global") return(#char_to_return) } However I'm getting the same result; the $is_number comparison only returns FALSE. Any ideas how I might accomplish this? Quote Link to post Share on other sites
HelloInsomnia 1103 Posted October 4, 2018 Report Share Posted October 4, 2018 $is number is returning "True" and you are checking for "true" (I know it shouldn't be like that maybe open a tracker report) Try this: set(#x,"abcd123efg","Global") add list to list(%chars,$list from text($character list(#x),$new line),"Delete","Global") set(#numbers,0,"Global") set(#letters,0,"Global") with each(%chars,#y) { if($is number(#y)) { then { increment(#numbers) } else { increment(#letters) } } } 1 Quote Link to post Share on other sites
Wolfman 0 Posted October 4, 2018 Author Report Share Posted October 4, 2018 Thank you, that is a little counter-intuitive Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.