ACSII <--> String

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

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 796
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Contact:

ACSII <--> String

Post by Jan Lichtenbelt »

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: 756
Joined: Wed May 31, 2017 11:57 am
Contact:

Re: ACSII <--> String

Post by mnf »

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: 796
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Contact:

Re: ACSII <--> String

Post by Jan Lichtenbelt »

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: 756
Joined: Wed May 31, 2017 11:57 am
Contact:

Re: ACSII <--> String

Post by mnf »

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

kersing
Valued Contributor
Valued Contributor
Posts: 1939
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Contact:

Re: ACSII <--> String

Post by kersing »

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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 756
Joined: Wed May 31, 2017 11:57 am
Contact:

Re: ACSII <--> String

Post by mnf »

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.

User avatar
Benj
Matrix Staff
Posts: 14854
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: ACSII <--> String

Post by Benj »

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"

Post Reply