I have a string which contains "6" and I want to convert that string to an integer (or byte) so I can use it in a calculation. Which command do I need to use?
Bert
Convert string to integer (or byte)
- 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:
Hello Bert
Simply get the byte from the string you wish to use. This can be done by indexing the array eg string[3] will get the 4th character in variable string. There are also functions in the string manipulation that will get you a single character.
Then simply minus 48 or '0' from the number.
eg
number = string[3]
number = number - '0'
Simply get the byte from the string you wish to use. This can be done by indexing the array eg string[3] will get the 4th character in variable string. There are also functions in the string manipulation that will get you a single character.
Then simply minus 48 or '0' from the number.
eg
number = string[3]
number = number - '0'
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
- 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:
Well if you want to be really clever about it you can create a loop that scans ahead and sees if the next character in the string is a number (eg between 48 '0' and 57 '9' ). If it is then the current number gets multiplied by 10 and then the next number is added to create a running total of possible numeric characters (max 6).
However if you are only expecting numbers with a certain amount of digits then your approach is perfect.
However if you are only expecting numbers with a certain amount of digits then your approach is perfect.
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