Help with replacing part of a "string"
eagletalontim
Posts: 1,399
Hello all again! I am attempting to modify a DAT variable before it is sent to the server, but I can't seem to get the DATAHERE to replace with a number that is calculated.
I can replace the line in question with :
How can I replace the DATAHERE with a calculated number?
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 CR = $0D LF = $0A DAT DataSeg1 byte "GET /tims/post.php?data=DATAHERE HTTP/1.1", CR, LF, { } "Host: www.example.com", CR, LF, { } "User-Agent: Wiz5100", CR, LF, CR, LF, $0 OBJ str : "STRINGS2" pst : "Parallax Serial Terminal" VAR byte str_test[255] byte new_str[255] byte value PUB Main | strh pst.Start(115_200) pause(5000) value := (12345 + 12345) / 2 strh := @DataSeg1 bytefill(@str_test, 0, 255) bytemove(@str_test, strh, strsize(strh)) strh := str.StrReplace(@str_test, string("DATAHERE"), value) ' ******* Lost Here???? pst.str(strh) PRI pause(Duration) waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt) return
I can replace the line in question with :
strh := str.StrReplace(@str_test, string("DATAHERE"), string("12345"))and it works exactly as needed.
How can I replace the DATAHERE with a calculated number?
Comments
I have written a library that does what you need. It didn't get a lot of attention but you can find it here:
http://forums.parallax.com/showthread.php/148937-Concept-Test-General-Purpose-String-Output-Formatting
FDS+ also has a decimal to string function, although you'd have to modify it to write to a buffer instead of the tx() function.
-Phil