SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 2 Vol 1

STRING COMPARE AND REPLACE

Name:
    STRING COMPARE AND REPLACE
Type:
    Let Subcommand
Purpose:
    Compare a string to a list of strings and if a match is found define a replacement string.
Description:
    This is a specialized command that was developed to improve performance in the EST.DP macro used by the 10-step macros for the analysis of 2-level full or fractional factorial designs.

    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 loop
          
    In 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 loop
          
    This 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:
    LET <sout> = STRING COMPARE AND REPLACE <sorg> <sold> <srepl>
                            <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>.

Examples:
    LET STRING STNEW = STRING COMPARE AND REPLACE ...
                            SOLD SREPLACE S1 S2 S3 S4 S5 S6
    LET STRING STNEW = STRING COMPARE AND REPLACE ...
                            SOLD SREPLACE S1 TO S6
Default:
    None
Synonyms:
    None
Related Commands: Applications:
    Data Management
Implementation Date:
    2018/03
Program:
     
    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
Disclaimer | FOIA

NIST is an agency of the U.S. Commerce Department.

Date created: 04/04/2018
Last updated: 04/04/2018

Please email comments on this WWW page to alan.heckert@nist.gov.