No announcement yet.

Parsing a string of numbers

  • Filter
  • Time
  • Show
Clear All
new posts

  • Parsing a string of numbers

    Hello I am having troubles if anyone can help. I've been scouring the forums and I haven't found a solution.
    Using section 2.16.2 of the DIABLO16 Internal Functions document, I have generated the following code (an excerpt from a larger code):

        to(tempString);                     //Direct the Output stream for "print" to the string buffer
        print(curOxy);                      //Send the value in "curOxy" to the string buffer. Currently the number "352" is stored.
        strPtr1 := str_Ptr(tempString);   //Create a string pointer to the new string version of the curOxy WORD value
        while(str_GetD(&strPtr1,&parsedCurOxy[n]) != 0)       //Supposedly cycle through all values in the new string and store numbers in each             
            n:=n+2;                                                                     //element of "parsedCurOxy".
        print("parsedCurOxy[0] = ", parsedCurOxy[0], "\nparsedCurOxy[1] = ", parsedCurOxy[1], "\nparsedCurOxy[2] = ",
        parsedCurOxy[2], "\n");                 //When these values are printed, the first value is "352" and the next two are both zero.
    The issue, as stated in the code comments, is that instead of each element of "parsedCurOxy" being 3, 5, and 2, the first element contains 352 and the others contain zero. The Internal Functions document example is where I got the "while" code.

    The overall applications is to take an integer value (curOxy), parse out the numbers into individual variables, then use those variables in "img_Show" functions to have the screen display number images. So "352" would display on the screen as three separate images, if that makes sense.

    Any help is much appreciated!

  • #2
    Hi Cody-DCI,

    This forum post might be helpful:

    picking out data from a string

    It seems the technique suggested there is by subtracting each character in the string by '0'. This will convert it into the 'real' number instead of a 'char'.

    Incoming string -> "123" tempString = {'1','2','3',\0}...tempString[n] := n - '0';

    Hope this helps,