Hi guys,
I am trying to obtain a integer from a string in Processing2.
My Arduino code sending a string via serial port ;
the string is "-1" and Processing taking that string.
Now in Processing2 I need to parse that string to transform it into a integer number.
No problems when I obtaining positive values but when I need to obtain negative values troubles begin!
ok here what I have:
int myValue = 0; String myString = "";
In the main loop:
myValue = int(myString );
or myValue = parseInt(myString);
I repeat, if this integer value is positive so no problems and my program working good but if the integer value need to be negative so seems that the parse command can't understand the minus symbol... so "-1" can't be handled making my program crash.
What I need to parse a negative number from a string like "-1" ???
In my case I using parseInt command in Processing2 just to convert a string into an Integer.
In my Arduino code I have a integer value that I am sending via serial (then via String) to Processing2.
So when Processing receive this string I just need to convert this string into a integer again to obtain the original Arduino integer value.
I repeat that until my Arduino value is positive, my program working good! Just when Arduino value become negative so I can't make the String-Integer transformation in Processing2.
PaulS:
Why are you asking Processing questions on the Arduino forum? This question belongs on the Processing forum.
Of course, you COULD determine that the first character is a minus sign, strip it off, convert the rest, and then multiply by -1.
Ehh I have troubles in Processing2 forum cause I can't confirm my email (whatever it is) so I can't create topics.
My last chance is here!
So please can you tell me what is the command to check the singe string chars?
EDIT : solved! thx for the advice regard to check the first char!