ACSII <--> String

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

ACSII <--> String

Postby Jan Lichtenbelt » Sun Jul 14, 2019 12:13 pm

Who to change an ACSII value into a string?
Who to change a string (one symbol) into an ASCII value?

Kind regards

Jan

mnf
Valued Contributor
Valued Contributor
Posts: 530
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 294 times
Contact:

Re: ACSII <--> String

Postby mnf » Sun Jul 14, 2019 2:02 pm

Not quite sure what you're after?

'A' gives a string '65'
Or just "A" gives an integer 65
( x = str[0] )

Martin

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

Re: ACSII <--> String

Postby Jan Lichtenbelt » Sun Jul 14, 2019 3:14 pm

something like:
String S[0]=char(65) with results S="A"

and

Byte B= asci(S[0]) which should be 65

Kind regards

mnf
Valued Contributor
Valued Contributor
Posts: 530
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 294 times
Contact:

Re: ACSII <--> String

Postby mnf » Sun Jul 14, 2019 4:33 pm

Str[0] = 65 in a calculation box

Sets str[ 0]to 'A'

And c = str[0] does what you want too.
So if str = "ABC" str[0] =65, str[1] = 66 and str[2] = 67

Martin
These users thanked the author mnf for the post:
Jan Lichtenbelt (Sun Jul 14, 2019 7:29 pm)
Rating: 5.26%
 

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: ACSII <--> String

Postby kersing » Sun Jul 14, 2019 5:45 pm

Just keep in mind to not exceed the length of the string - 1 with the index (number between the brackets) and to add str[last index + 1] = 0 if you are not using the entire string length as declared in Flowcode to avoid surprises.
These users thanked the author kersing for the post (total 2):
Jan Lichtenbelt (Sun Jul 14, 2019 7:30 pm) • Benj (Mon Jul 15, 2019 9:52 am)
Rating: 10.53%
 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 530
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 294 times
Contact:

Re: ACSII <--> String

Postby mnf » Sun Jul 14, 2019 8:01 pm

Another useful tip is to use character constants instead of ASCII values.

So for example

x = c- '0' converts an ASCII character of '0'..'9' to its numerical equivalent. This is more readable but equivalent
x = c - 48

Note the use of single quotes.
These users thanked the author mnf for the post (total 2):
Benj (Mon Jul 15, 2019 9:52 am) • Jan Lichtenbelt (Mon Jul 15, 2019 2:03 pm)
Rating: 10.53%
 

User avatar
Benj
Matrix Staff
Posts: 14299
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4394 times
Been thanked: 4123 times
Contact:

Re: ACSII <--> String

Postby Benj » Mon Jul 15, 2019 9:51 am

You also need to remember to terminate the string. e.g. add a null byte to mark the end of the data.

For example

s[0] = 65
s[1] = 'x'
s[2] = 0

Would give you "Ax"
These users thanked the author Benj for the post:
Jan Lichtenbelt (Mon Jul 15, 2019 2:02 pm)
Rating: 5.26%