extract number from string buffer
phishguy
Posts: 36
I just started using the propeller a week ago and I think it's great. I have written a program that will capture text from a serial port and log it to a sd card file. I create the file name with a format of DFLG0001.txt. I would like to be able to extract the numeric part of that string into a variable from the buffer when I do a nextfile. That way I can find the largest number used and increment the variable for the next created file. However, being quite new at spin code,·I can't figure out how to do this. Any examples for doing this would be greatly appreciated.
·
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thanks for pointing me in the right direction. I was able to adapt the getdec routine for my purpose.
Because I am a beginner, I was wondering if anyone could critique my code and let me know if I'm doing anything wrong or if I should be doing things in a different or better way.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
If you need a decimal value of the numeric string, then you may need to use the Simple Numbers object (included with the Propeller Tool). Or possibly a combination of the two is a simple/surer way to do what you are trying to do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Your code apparently does what you want it to, so that's the most important thing, but I have a few questions/comments about getDec.
First, why do you bother copying from tbuf to DataIn?
Second, you copy values into DataIn[noparse][[/noparse] 5]..DataIn[noparse][[/noparse]8], but then you look at DataIn[noparse][[/noparse]7]..DataIn[noparse][[/noparse]0]. DataIn[noparse][[/noparse]8] is unnecessary and DataIn[noparse][[/noparse]0..4] are unassigned.
The "if ptr > 2" test is unnecessary, since ptr will always be 9.
Assignments such as "value := value + something" or "place := place * 10" can be written "value += something" and "place *= 10". Saves typing, saves reading, and generates more compact code.
Also, you could change "value := value * -1" to just "-value".
And "value :=value" does nothing but waste time and memory. You could just drop the whole "elseif Datain[noparse][[/noparse]0] == '+'" thing.
Are you really expecting negative numbers?