OriginLab Corporation - Data Analysis and Graphing Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis                     
 
Skip Navigation Links
All BooksExpand All Books
LabTalk ProgrammingExpand LabTalk Programming
LabTalk Scripting GuideExpand LabTalk Scripting Guide
Language FundamentalsExpand Language Fundamentals
Special Language FeaturesExpand Special Language Features

2.3.2.5 String registers

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, as needed. 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, the following 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, as in the following example:

// Deletes the current active dataset:

del %C;

%@ String Registers

The following read-only system string registers comprised of %@-characters followed by a single alphabetic character, are added beginning with Origin 2016 SR2:

 %@ Variable Description
 %@A The Apps root installation folder.
 %@D The ProgramData folder where data and configuration for Origin operations are stored.
 %@F The name of the active Project Explorer folder.
 %@H The book name that contains the active embedded graph.
 %@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 to the Origin EXE, including the name of the EXE. Works with 32- or 64-bit versions. If both versions are installed, %@O returns the path to the EXE that is running.
 %@P The full Project Explorer path of the active folder.
 %@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.
 %@Y User AppData Root folder. This folder stores the xml file that lists installed apps and their version number.

String Registers as String Variables

Except the system variable string registers, you can use string registers as string variables, 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 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 returns the specified portion of a string. The general form of this notation is:

%[string, argument];

where string contains the string itself, and argument specifies which portion of the string to return.

For the examples that follow, enter this assignment statement in the Script window:

%A = "Results from Data2_Test"

The following examples illustrate the use of argument in substring notation:

To do this: Enter this script: Return value:
Search for a character and return all text to the left of the character.
%B = %[%A, '_']; %B =
Results from Data2
Search for a character and return all text to the right of the character.
%B = %[%A, >'_']; %B =
Test
Return all text to the left of the specified character position.
%B = %[%A, 8]; %B =
Results
Return all text between two specified character positions (inclusive).
%B = %[%A, 14:18]; %B =
Data2
Return the #n token, counting from the left.
%B = %[%A, #2]; %B =
from
Return the length of the string.
ii = %[%A]; ii =
ii = 23

Other examples of substring notation:

To do this: Enter this script: Return value:
Return the ith token separated by a specified separator (in this case, a tab)
%A = 123	342	456;
for (ii = 1; ii <= 3; ii++)
{
   Book1_A[ii] = %[%A, #ii,\t]
};
Places the value 123 in Book1_a[1], 342 in Book1_a[2], and 456 in Book1_a[3].
Return the @n line
%Z = "First line
second line";
%A = %[%Z, @2];
Places the second line of the %Z string into %A. To verify this, type %A = in the Script window.

Note:

When using quotation marks in substring or substitution notation:

  • Space characters are not ignored.
  • String length notation includes space characters.

For example, to set %A equal to 5 and find the length of %A, type the following in the Script window and press Enter:

%A = " 5 ";
ii = %[%A];
ii = ;

Origin returns: ii = 3.

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
 

© OriginLab Corporation. All rights reserved.