Who to change an ACSII value into a string?
Who to change a string (one symbol) into an ASCII value?
Kind regards
Jan
ACSII <--> String
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
-
- Valued Contributor
- Posts: 1189
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: ACSII <--> String
Not quite sure what you're after?
'A' gives a string '65'
Or just "A" gives an integer 65
( x = str[0] )
Martin
'A' gives a string '65'
Or just "A" gives an integer 65
( x = str[0] )
Martin
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: ACSII <--> String
something like:
String S[0]=char(65) with results S="A"
and
Byte B= asci(S[0]) which should be 65
Kind regards
String S[0]=char(65) with results S="A"
and
Byte B= asci(S[0]) which should be 65
Kind regards
-
- Valued Contributor
- Posts: 1189
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: ACSII <--> String
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
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
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: ACSII <--> String
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
― C.S. Lewis
-
- Valued Contributor
- Posts: 1189
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: ACSII <--> String
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.
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.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: ACSII <--> String
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"
For example
s[0] = 65
s[1] = 'x'
s[2] = 0
Would give you "Ax"
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel