2.3.2.2.1 String Registers and String Register Substitution

Introduction

String Registers are one means of handling string data in Origin. Before Version 8.0, they were the only way and, as such, current versions of Origin continue to support the use of string registers. However, users are now encouraged to migrate their string processing routines toward the use of proper string variables, see String Processing for comparative use.

Long-time LabTalk scripters know string register names to be comprised of a %-character followed by a single alphabetic character (a letter from A to Z). Of these original 26 string registers, i.e., %A--%Z, some are reserved as system string registers (listed in the table, below).

Starting with Origin 2016 SR2, "%@N" read-only system string registers are being added. You will find those listed in a second table below the original "%N" string registers.

String registers are of global scope; this means that they can be changed by any script at any time. Sometimes this is useful, other times it is dangerous, as one script could change the value in a string register that is being used by another script with erroneous and confusing results.

Some string registers are reserved for use as system variables, and attempting to assign values to them could result in errors in your script. They are grouped in the ranges %C--%I, and %X--%Z, or are preceded by a %@ (e.g. %@A = Apps root folder). Consult the tables below.

String Registers as System Variables

String registers hold up to 260 characters (%Z holds up to 6290). String register names are comprised of a %-character (or %@), followed by a single alphabetic character (a letter from A to Z); for this reason, string registers are also known as % variables.

% String Registers

Of the 26 possible string registers, those listed in this table are reserved as system variables that have a special meaning, and they should not be reassigned in your scripts. It is often helpful, however, to have access to (or operate on) the values they store.

 % Variable Description
 %C The name of the current active dataset.
 %D Current Working Directory, as set by the cd command. (New in Origin 8)
 %E The name of the window containing the latest worksheet selection.
 %F The name of the dataset currently in the fitting session.
 %G The current project name.
 %H The current active window title.
 %I The current baseline dataset.
 %X The path of the current project.
 %Y

The full path name to the User Files folder, where the user .INI files as well as other user-customizable files are located. %Y can be different for each user depending on the location they selected when Origin was started for the first time.

Prior to Origin 7.5, the path to the various user .INI files was the same as it was to the Origin .EXE. Beginning with Origin 7.5, we added multi-user-on-single-workstation support by creating a separate "User Files" folder.

To get the Origin .EXE path(program path), use the following LabTalk statement:

%a = system.path.program$

In Origin C, pass the appropriate argument to the GetAppPath() function (to return the INI path or the EXE path).

 %Z A long string for temporary storage. (maximumn 6290 characters)


String registers containing system variables can be used anywhere a name can be used. While you should not reassign values to system string registers, it is often helpful to have access to (or operate on) the system values they store, for instance...

// Deletes the current active dataset:

del %C;

%@ String Registers

A second set of read-only system string registers comprised of %@-characters followed by a single alphabetic character was added in Origin 2016 SR2.

 %@ Variable Description
 %@A The Apps root installation folder.
 %@B The OriginLab AppData folder.
 %@C The Computer Name.
 %@D The ProgramData folder where data and configuration for Origin operations are stored.
 %@E The Group Folder Path of the Group Leader Machine. See Set Group Folder Location Dialog.
 %@F The name of the active Project Explorer folder.
 %@G The graph page short name of the active graph sheet (graph added to workbook as sheet). Empty if not this type of sheet or no contained graph.
 %@H The book name that contains the active embedded graph or matrix page.
 %@I The last active window short name.
 %@J The path of the Origin EXE folder (see %@O, below).
 %@L OriginLab software license owner name.
 %@M Newly appended file path, including extension.
 %@N Name of the most recently created window, whether shown, hidden or deleted. Contrast with %H, which stores the name of the active window.
 %@O The full path of the Origin EXE, including the name of the EXE.
 %@P The full Project Explorer path of the active folder.
 %@Q Current Origin Project file extension (lower-case opj or opju).
 %@R The ProgramData root folder where Origin downloads patch files (\Updates) and Help files (\Localization) are stored. Opens with the menu command Help: Open Folder: Program Data Folder.
 %@S User Name entered in the Origin Setup dialog box during installation.
 %@T The title (short name + long name if it exists) of the active graph sheet (graph added to workbook as sheet). Empty if not this type of sheet or no contained graph. Can equal %@G if graph does not have a long name.
 %@U The project Unsaved Files path.
 %@V The Temp Save folder. This folder is used to save the files during the project saving.
 %@W Company Name entered in the Origin Setup dialog box during installation.
 %@X Currently executing Apps folder.
 %@Y User AppData Root folder. This folder stores the xml file that lists installed apps and their version number.

String Registers as String Variables

Using a string register -- in which the content of the string register is substituted during script execution -- is the simplest form of substitution. String registers were used exclusively in older scripts, before the introduction of string variables (Origin 8). With the exception of the system string registers listed above, you can use string registers as string variables, as demonstrated in the following examples:

Assigning Values to a String Variable

Entering the following assignment statement in the Script window:

%A = John

defines the contents of the string variable %A to be John.

String variables can also be used in substitution notation. Using substitution notation, enter the following assignment statement in the Script window:

%B = %A F Smith

This sets %B equal to John F Smith. Thus, the string variable to the right of the assignment operator is expressed, and the result is assigned to the identifier on the left of the assignment operator.

As with numeric variables, if you enter the following assignment statement in the Script window:

%B =

Origin returns the value of the variable:

John F Smith

Expressing the Variable Before Assignment

By using parentheses, the string variable on the left of the assignment operator can be expressed before the assignment is made. For example, enter the following assignment statement in the Script window:

%B = Book1_A

This statement assigns to the string register %B, the value Book1_A. If Book1_A is a dataset name, then entering the following assignment statement in the Script window:

(%B) = 2*%B

results in the dataset being multiplied by 2. String register %B, however, still contains the string Book1_A.

String Comparison

When comparing string registers, use the "equal to" operator (==).

  • If string registers are surrounded by quotation marks (as in, "%A"), Origin literally compares the string characters that make up each variable name. For example:
aaa = 4;
bbb = 4;
%A = aaa;
%B = bbb;
if ("%A" == "%B")
    type "YES";
else
    type "NO";

The result will be NO, because in this case aaa != bbb.

  • If string registers are not surrounded by quotation marks (as in, %A), Origin compares the values of the variables stored in the string registers. For example:
aaa = 4;
bbb = 4;
%A = aaa;
%B = bbb;
if (%A == %B)
    type "YES";
else
    type "NO"

The result will be YES, because in this case the values of the strings (rather than the characters) are compared, and aaa == bbb == 4.

Substring Notation

Substring notation %[ string, [argument1], [argument2] ] returns string length if no arguments or a substring specified by argument1 and argument2.

To do this: Arguments Enter this script: Return value:
Returns length of string. If no quote around the string, space on both sides will be ignored NA
%A="     hello     "; 
type %[%A];
%B=     hello     ;
type %[%B];
15 
5
Search for a character and return all text to the left of the character. '<char>'
%A = "Results from Data2_Test";
%B = %[%A, '_']; 
%B =
Results from Data2
Search for a character and return all text to the right of the character. >'<char>'
%A = "Results from Data2_Test";
%B = %[%A, >'_']; %B =
Test
Return all text to the left of the n th character position. n
%A = "Results from Data2_Test";
%B = %[%A, 8]; %B =
Results
Return all text between two specified character positions n:m (inclusive). 14:18
%A = "Results from Data2_Test"; 
%B = %[%A, 14:18]; %B =
Data2
Return the #n token, counting from the left. #n
%A = "Results from Data2_Test"; 
%B = %[%A, #2]; %B =
from
Return the @n line @n
%A = "First line
second line";
%Z = %[%A, @2];
%Z=;
Assign the 2nd line of %A string into %Z
Returns a substring based on taken and specified separator. #n , <separator>
%A = 123	342	456;
for (ii = 1; ii <= 3; ii++)
{
   Book1_A[ii] = %[%A, #ii,\t]
};
Book1's column A will be filled with
123
342
456

A Note on Tokens

A token can be a word surrounded by white space (spaces or TABS), or a group of words enclosed in any kind of brackets. For example, if:

%A = These (are all) "different tokens"

then entering the following in the Script window:

Scripts Returns
%B = %[%A, #1]; %B=
These
%B = %[%A, #2]; %B=
are all
%B = %[%A, #3]; %B=
different tokens