Convert a character to its numerical value

For general Flowcode discussion that does not belong in the other sections.
Post Reply
alanwms
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

Post by alanwms »

I notice that "stringtoint" does not allow operation of alpha chars. Only numeric chars. Do we have a method of doing that?

mnfisher
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

Post by mnfisher »

What are you trying to achieve?

For example 'A' do you want 10 (hex value) or 65 ASCII value?

Martin

alanwms
Posts: 133
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 26 times
Been thanked: 7 times

Re: Convert a character to its numerical value

Post by alanwms »

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?

mnfisher
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

Post by mnfisher »

If you want the ASCII value 'A' = 65 = 0x41

So for a string :

Code: Select all

value = str[0]
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

Code: Select all

value = 'A'
note the single quote ' instead of double quote "

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'
to check if c is a digit for example


Martin

alanwms
Posts: 133
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 26 times
Been thanked: 7 times

Re: Convert a character to its numerical value

Post by alanwms »

Martin - You are the man!

Thank you for that tid bit.

Post Reply