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 EDIT

Name:
    STRING EDIT
Type:
    Let Subcommand
Purpose:
    Edit the contents of a string.
Description:
    This command allows you to edit the contents of a previosuly defined string.

    The STRING EDIT command involves three string:

    1. The original string which we will call SORG.

    2. A substring, which we will call SOLD, that contains the text to be changed.

    3. A substring, which we will call SNEW, which contains the replacement text.

    The STRING EDIT command searches the string SORG for the substring SOLD. If found, it replaces the SOLD text with the SNEW text. If no match is found, an error message is printed and the new string is not created.

Syntax 1:
    LET <sout> = STRING EDIT <sorg> <sold> <snew>
    where <sout> is the name of the resulting string;
                <sorg> is the name of the original string to be edited;
                <sold> is the name of the match string;
    and <snew> is the name of the replacement string.

    This syntax edits the first occurence of <sold> only.

Syntax 2:
    LET <sout> = STRING GLOBAL EDIT <sorg> <sold> <snew>
    where <sout> is the name of the resulting string;
                <sorg> is the name of the original string to be edited;
                <sold> is the name of the match string;
    and <snew> is the name of the replacement string.

    This syntax edits all occurence of <sold>.

Examples:
    LET STRING S1 = filexx.dat
    LET STRING S2 = xx
    LET STRING S3 = 23
    LET SOUT = STRING EDIT S1 S2 S3
    LET SOUT = STRING GLOBAL EDIT S1 S2 S3
Note:
    The name of the new string can be the same as the original string. For example,

      LET FNAME = STRING EDIT FNAME SOLD SNEW
Note:
    All three 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 EDIT FNAME ".dat" ".txt"

    you need to do

      LET STRING SOLD = .dat
      LET STRING SNEW = .txt
      LET FNAME = STRING EDIT FNAME SOLD SNEW
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.
Note:
    Only the first occurrence that is matched is changed. That is, there is currently no "global" option and no option to specify that the second or third or last occurence be changed.

    Also, there is currently no support for wild cards or regular expressions.

    Note: The 2015/02 version of Dataplot added a global option (see Syntax 2 above).

Note:
    If you want the replacement string to be null (i.e., you want to delete the match string), then you can do the following

      LET STRING SOUT = NULL()
      LET SOUT = STRING EDIT STIN SOLD SNEW

    or

      LET SOUT = STRING EDIT STIN NULL() SNEW

    The use of "NULL()" is currently specific to this command.

Default:
    None
Synonyms:
    None
Related Commands: Applications:
    Data Management
Implementation Date:
    2008/11
    2015/02: Support for STRING GLOBAL EDIT
    2015/02: Support for "NULL()" for replacement string
Program 1:
     
    LET STRING S1 = file23.dat
    LET STRING S2 = dat
    LET STRING S3 = txt
    LET SOUT = STRING EDIT S1 S2 S3
        
    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 = filexx.dat
    LET STRING S3 = xx
    TITLE CASE ASIS
    LOOP FOR K = 1 1 10
           LET STRING S2 = ^K
           LET FNAME = STRING EDIT SOLD S3 S2
           READ ^FNAME  Y X
           TITLE Data from File ^SOUT
           PLOT Y X
           DELETE Y X
    END OF LOOP
        

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