I need to convert a signed long received from a GPS module into a string that can be POSTed to a web site. I have been working with a function like this:
// ScaleL4 will scale a long input by scale factor. Ex: ScaleL4( -1172483001,-7) = "-117.2483001"
String ScaleL4(long lonInput,int scale)
{
String strLeft;
String strRight;
String strIn ;
String strOut ;
strIn = "";
strIn += lonInput;
if (scale == 0)
{
strOut = strIn;
}
if (scale < 0)
{ // Scale smaller
int pos = (strIn.length() )+ scale;
strLeft = strIn.substring(0,pos);
strLeft += '.';
strRight = strIn.substring(pos);
strOut = strLeft +=strRight;
}
return strOut;
}
The code seems to work once or twice then blows up when called again. The strOut returned has changed characters in it or becomes a huge String and destroys the sketch its running in. The problem seems to be centered around the way the strRight is created. A lot of the time the call to strIn.substring(pos) simply never returns.
I get the feeling that the String library is buggy.
Am I right?