Case with String
Ltech
Posts: 380
in Propeller 1
I try to get my stuff compact.
In try to change
It works try to cleanup with "case" statement
Like
Somebody an direction ?
Thanks
In try to change
elseif STR.startsWithCharacters(STR.tokenizeCharacters(@filename[0]), String("INITIAL")) == TRUE do x elseif STR.startsWithCharacters(STR.tokenizeCharacters(@filename[0]), String("LEFT")) == TRUE do y......
It works try to cleanup with "case" statement
Like
case STR.tokenizeCharacters(@filename[0]) string("INITIAL") : do x string("LEFT") : do yAnd it will not do it
Somebody an direction ?
Thanks
Comments
The line "string("INITIAL")" produces an address where "INITIAL" is stored in RAM. Each string statement will produce a new address so you can't compare this way.
Here's one way I've used. This technique will only compare the first four characters so you need to make sure the first four characters of each string are unique.
By defining the strings as longs before listing the characters in the string, the first four characters of the string can be treated as an independent long value.
Again, the limit of doing it this way is only the first four bytes of the string are tested. If a string has fewer than four characters, it should be padded with zeros at the end so it makes up a full long (though I'm not positive this is needed).
The above is an unconventional way to testing strings. For a more conventional way you can see how it's done in the Eddie firmware.
https://github.com/ddegn/EddieFirmware
The file "Eddie.spin" should show how this is done. If you want a complete program, download one of the archives.
Here's a section showing how "strcmp" is used.
The string being compared needs to be the correct case and stored in the buffer named "InputBuffer."