String Lookup Routines
Shane M
Posts: 58
Hello everyone.· I have a question. I can think up a few solutions but I don't want to write a lage amount of code to find there was a much more efficient way.
Bottom line I am accepting serial text strings that are 16 characters or less.· Matching the string with a much longer string that I will send via the emic text-to-speech chip.· Here is an example of strings that I am receiving:
"message1"
"message2"
"message3"
So if the string is "message1" I will have stored in·memory (data area)·somewhere "This is message one".· So that each time I receive the string "message1", I will lookup the matching text-to-speech text.
I already have the propellor receiving messages in one cog.· I have another cog checking a string variable -- if it has changed, I can run a sub routine (currently I just have the emic say the received message but here I will put the MessageLookup routine).·
I need to create·a subroutine that will match the received message with values in memory and then point me the to the memory position of the matching text string.
Any ideas or commands I'll find useful to do this?
I considered a "case"· or "lookdown" but it doesn't seem it will handle the string the way I need.
Can anyone give me some advice.
Thanks in advance.
·
Bottom line I am accepting serial text strings that are 16 characters or less.· Matching the string with a much longer string that I will send via the emic text-to-speech chip.· Here is an example of strings that I am receiving:
"message1"
"message2"
"message3"
So if the string is "message1" I will have stored in·memory (data area)·somewhere "This is message one".· So that each time I receive the string "message1", I will lookup the matching text-to-speech text.
I already have the propellor receiving messages in one cog.· I have another cog checking a string variable -- if it has changed, I can run a sub routine (currently I just have the emic say the received message but here I will put the MessageLookup routine).·
I need to create·a subroutine that will match the received message with values in memory and then point me the to the memory position of the matching text string.
Any ideas or commands I'll find useful to do this?
I considered a "case"· or "lookdown" but it doesn't seem it will handle the string the way I need.
Can anyone give me some advice.
Thanks in advance.
·
Comments
Look at the command StrComp page 203 in the manual.
But also why not use numerics instead of "message 1" etc. why not use 1 or even just "1"
this would of course off put the burden of deciding the string on the SENDER program which
if is a PC can do more extensive string manipulation.
Thus all you have to do is send one byte as a numeric 0-255 or as a character "1" etc.
and then all you have to do on the propeller is use numerical comparison.
However, look at the StrComp command if you really need to.
Samuel
Strcomp is what I considered and use in the code. I didn't know of an elegant way to lookup the text related to the message.
I agree that a number would be easier. However I'm communicating with a PLC and the only option I have is ASCII RS-232 messages.
Thanks!
They mimic PHP functions of the same name. But there are string searching, parsing, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
I made some changes. I sped things up as well as fixed substr to work more like PHP's function.
You can download the latest version here: obex.parallax.com/objects/502/
If anyone else has string function similar to this, it would be nice to have them all in one library on the OBEX, please post them, and I can add it into the file (cited of course).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Changes since 1.0: Added StrReplace, Combine, StrRev, Trim, StrPad, Capitalize, StrRepeat, and StrParse. Fixed SubStr's negative values. Removed STR_MAX_LENGTH limit from StrPos. And major speed updates between each of the releases.
Download it here: obex.parallax.com/objects/502/
Anyone know why searching for "Strings Library" or "Strings" in the Obex does not return this object?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shane Merem
www.websiteforge.com
www.magnusoft.com
·
http://forums.parallax.com/showthread.php?p=613308
I fixed the link (above)...
When I tried to fix it in the browser it took me to the HTTP Wikipedia page, weird.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!