![]() |
STRING COMPARE AND REPLACEName:
The specific code that motivated this command was loop for j1 = 1 1 numeff let string stefc^j1 = -999 let string stprobe = ^stmain^j1 loop for j2 = 1 1 numconf let string starch = ^stt^j2 if stprobe = starch let string stefc^j1 = ^stc^j2 end if end loop end loopIn this code, we are looping over the main factors. For each main factor, a string is compared to a list of strings. The numconf parameter defines the number of strings being compared. This value can grow fairly large. For example, for a 2**(8-4) design, numconf is 96. If a match is found, a new string (stefc^j1) is set to a string that is not in the list being compared (^stc^j2). The updated code using the STRING AND REPLACE command is loop for j1 = 1 1 numeff let string stefc^j1 = -999 let stefc^j1 = string compare and replace stmain^j1 ... stc stt1 to stt^numconf end loopThis command eliminates the inner loop. For our 2**(8-4) example, this reduces the number of loop iterations from 8*96 = 768 to 8. The string stmain^j1 is being compared to the strings stt1 to stt^numconf. If stt9 matches stmain^j1, the stefc^j1 is set equal to stc9. That is, the replacement string defines a base name to which the index of the matching string is appended to define the replacement string name. If in our example, the string "stc" is a previously defined string, then this would be used rather than "stc9". Syntax:
<sc1> ... <sck> where <sout> is the name of the resulting string; <sorg> is a pre-existing string that will be compared to each of <sc1> ... <sck> <srepl> is pre-existing string that will be set to <sout> if a match is found; and where <sc1> ... <sck> is a list of pre-existing strings. If <srepl> does not exist but <srepl1> ... <sreplk> do exist, the replacement string will be <sreplj> where j denotes the index of the match. If no match is found, <sout> will not be created. The TO syntax can be used for <sc1> ... <sck>.
SOLD SREPLACE S1 S2 S3 S4 S5 S6 LET STRING STNEW = STRING COMPARE AND REPLACE ... SOLD SREPLACE S1 TO S6
LET STRING S1 = One LET STRING S2 = Two LET STRING S3 = Three LET STRING S4 = Four LET STRING S5 = Five . LET STRING SOLD = Four LET STRING SREPL = String Found LET STRING SNEW = String Not Found LET STRING SNEW = STRING COMPARE AND REPLACE ... SOLD SREPL S1 TO S5 PRINT "SNEW: ^SNEW"The following output is generated SNEW: String Found
|
Privacy
Policy/Security Notice
NIST is an agency of the U.S.
Commerce Department.
Date created: 04/04/2018 |