Convert a character to its numerical value
-
- Posts: 133
- http://meble-kuchenne.info.pl
- Joined: Fri Dec 04, 2020 2:29 pm
- Has thanked: 26 times
- Been thanked: 7 times
Convert a character to its numerical value
I notice that "stringtoint" does not allow operation of alpha chars. Only numeric chars. Do we have a method of doing that?
Re: Convert a character to its numerical value
Sure - I would like to stringtoint$("A") to have an outcome of 41 (I think that's the equate).
Currently I am achieving this with the function compare with "". That seems to give me an equivalency.
Wouldn't it be great to use stringtoint$ to get the equivalent decimal?
Currently I am achieving this with the function compare with "". That seems to give me an equivalency.
Wouldn't it be great to use stringtoint$ to get the equivalent decimal?
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Convert a character to its numerical value
If you want the ASCII value 'A' = 65 = 0x41
So for a string : in a calculation block
Will get the value of the first character of the string
Or if you just want the value of a character
note the single quote ' instead of double quote "
You can use a character constant instead of a constant to make your code more readable to check if c is a digit for example
Martin
So for a string :
Code: Select all
value = str[0]
Will get the value of the first character of the string
Or if you just want the value of a character
Code: Select all
value = 'A'
You can use a character constant instead of a constant to make your code more readable
Code: Select all
If c >= '0' and c <= '9'
Martin