Clovertech
› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › creating a list of hl7 escaped characters
I want to create a list of hl7 escaped characters in a proc I am writing.
F S T R E
I can’t seem to get it to work. suggestions?
Gary,
Would this work for you?
% set mylist [list \F\ \S\ \T\ \R\ \E\]
Then, for example, if you do:
% lindex $mylist 2 you get T
That seems to be correct.
Here is what I did:
set stuff
That gives a list called stuff which when echoed has this:
\T\ \S\
That looks wrong however when you extract each element (maybe via lindex) you will get T or S, etc. which is what you want.
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
Follow up question–>
how can I get lsearch to work with this list using the whole msg as a string?
set escaped_chars [list \F\ \S\ \T\ \R\ \E\] set chkmsg [crange $msg 9 end] if {[lsearch $escaped_chars $chkmsg] == 1} { do something here…. }
always returns -1 :cry:
You alwasy get -1 one because the way lsearch works isn’t how you are trying to use it.
lsearch doesn’t use the list of escape characters to see if one of them exists in your entire message.
Instead it is the other way around.
It is comparing your entire message to see if it matches one of your escape characters, which will never be true.
Here are some examples to illustrate:
lsearch {a b c d e} c
returns 2
lsearch {a b c d e} “message with c in it”
returns -1
lsearch {a b c d e {message with c in it}} “message with c in it”
returns 5
Russ Ross RussRoss318@gmail.com
I don’t really understand what you are trying to do. I assume you want to know if the message contains escape characters
foreach ch $escaped_chars {
set loc [lsearch $chkmsg $ch]
if {$loc >= 0} }
echo Escape charactor $ch located at index $loc
}
Yep Charlie that what I was attempting to do. I ended up do an regexp instead.