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 REPLACE

Name:
    STRING REPLACE
Type:
    Let Subcommand
Purpose:
    Insert the contents of one string into another string at a specified position.
Description:
    This command is used to insert the contents of one string into an arbitrary position of another string. For example, if the original string is

      FILExx.DAT

    and the insertion string is

      99

    and the replacement position is given as 5, then the resulting string would be

      FILE99.DAT

    Note that the replacement string overwrites the contents of the original string. Also note that if the the replacement position is 5, then the replacement string starts at position 5 (i.e., the position parameter is the before position rather than the after position).

    The STRING MERGE command performs a similar function. However, the original string is shifted to the right at the replacement position rather than overwritten. In the above example, the resulting string from the STRING MERGE command would be

      FILE99xx.DAT

    The STRING EDIT command can be used to perform more general edits of a string.

Syntax:
    LET <sout> = STRING REPLACE <sorg> <snew> <nstart>
    where <sout> is the name of the resulting string;
                <sorg> is the name of the original string;
                <snew> is the name of the replacement string;
    and <nstart> is the replacement position.
Examples:
    LET SOUT = STRING REPLACE S1 SNEW NSTART
Note:
    The name of the new string can be the same as the original string. For example,

      LET FNAME = STRING REPLACE FNAME SNEW NSTART
Note:
    Both strings on the right hand side of the equal sign must be previously existing strings. That is, expressions are not allowed. For example, instead of

      LET FNAME = STRING REPLACE FNAME ".dat" NSTART

    you need to do

      LET STRING SNEW = .dat
      LET FNAME = STRING REPLACE FNAME SNEW NSTART

    The starting position can be either a parameter or a numeric value. However, it cannot be a numeric expression. So

      LET FNAME = STRING REPLACE FNAME SNEW NSTART LET FNAME = STRING REPLACE FNAME SNEW 5

    are both allowed but

      LET FNAME = STRING REPLACE FNAME SNEW NLEN/2

    is not allowed. You would need to enter this as

      LET NSTART = NLEN/2
      LET FNAME = STRING REPLACE FNAME SNEW NSTART
Note:
    The total number of characters that DATAPLOT can use for storing functions and strings is set when DATAPLOT is built. The current default (11/2008) is 50,000 characters. Previous versions may set this limit at 1,000 or 10,000 characters. This limit applies to the combined number of characters for all functions and strings.
Default:
    None
Synonyms:
    None
Related Commands: Applications:
    Data Management
Implementation Date:
    11/2008
Program 1:
     
    LET STRING S1 = filexx.dat
    LET STRING S2 = 23
    LET NPOS = 5
    LET SOUT = STRING REPLACE S1 S2 NPOS
        
    The resulting string SOUT will contain

      file23.txt
Program 2:
     
    .  Assume we have variables X and Y in the files "file1.dat" to
    .  "file10.dat" and we want to plot each of these in turn.
    .
    LET STRING SOLD = filex.dat
    LET NPOS = 5
    TITLE CASE ASIS
    LOOP FOR K = 1 1 9
        LET STRING S2 = ^K
        LET FNAME = STRING REPLACE SOLD S2 NPOS
        READ ^FNAME  Y X
        TITLE Data from File ^SOUT
        PLOT Y X
        DELETE Y X
    END OF LOOP
        

Date created: 12/4/2008
Last updated: 12/4/2008
Please email comments on this WWW page to alan.heckert@nist.gov.