Shop OBEX P1 Docs P2 Docs Learn Events
deleting sections of char arrays — Parallax Forums

deleting sections of char arrays

atekippeatekippe Posts: 15
edited 2004-11-15 15:54 in General Discussion
does anyone know if you can delete part of a character array or parse it·to 4 specific numbers.· What I"m trying to do is extrapolate the numerics in this string which is outputted from a measuring device?· Is it like the buffer.delete command?

ePEAK 0.0076 in.

Thanks

atekippe
ISU·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-11-15 15:54
    You can use the bscanf() method in class Format.
    If your input string is stored in a char array:

    static char[noparse]/noparse myArray = new char[noparse][[/noparse]100];

    Suppose your string "ePEAK 0.0076 in" starts at offset 12

    static int[noparse]/noparse digit0 = new int[noparse][[/noparse]1];
    static int[noparse]/noparse digit1 = new int[noparse][[/noparse]1];
    static int[noparse]/noparse digit2 = new int[noparse][[/noparse]1];
    static int[noparse]/noparse digit3 = new int[noparse][[/noparse]1];
    int k = 12; //set offset
    k = Format.bscanf(myArray,k,"ePEAK 0.%1.1d",digit0);·//load 0 into digit0[noparse][[/noparse]0]
    k = Format.bscanf(myArray,k,"%1.1d",digit0);·//load 0 into digit1[noparse][[/noparse]0]
    k = Format.bscanf(myArray,k,"%1.1d",digit0);·//load 7 into digit2[noparse][[/noparse]0]
    k = Format.bscanf(myArray,k,"%1.1d",digit0);·//load 6 into digit3[noparse][[/noparse]0]

    or use a single int to store the fraction (4 digits is 0-9999)
    k = Format.bscanf(myArray,k,"ePEAK 0.%4.4d",digit0);·//load 0076 into digit0[noparse][[/noparse]0]

    You find the Format class here:
    http://groups.yahoo.com/group/javelinstamp/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/

    There is also a sscanf() method, but this always starts scanning at offset 0.

    regards peter
Sign In or Register to comment.