String

 

Between

This function extracts a substring using begin and end strings or characters.

Syntax

string str1$ = str.Between(str2$,str3$);

Return

Returns the string contents after str2 and before str3. Returns an empty string if either str2 or str3 are not found.

SeeAlso

Mid

Examples

string strIn$=[Results]"March 2009"!"Average Return"[1:31];
string strOut$ = strIn.Between("[","]")$;   // strOut is Results
string strOut$ = strIn.Between("]","!")$;   // strOut is "March 2009"
string strOut$ = strIn.Between("!","[")$;   // strOut is "Average Return"

Code

This function returns the ASCII code for the first character of the string.

Syntax

int code = str.Code();

Return

Returns the ASCII code of the first character of the string, if the string is empty, return 0.

Examples

string str$ = "ABC";
int code = str.Code();  // code = 65

Compare

This function performs a case-sensitive comparison of the string with another string.

Syntax

int nRet = str.Compare(str2$);

Return

0 if the strings are identical, < 0 if this string object is less than str2$ in the dictionary order, or > 0 if this string object is greater than str2$.

SeeAlso

CompareNoCase

Examples

string str0$ = "ijk";
i0 = str0.Compare("ijk"); i0 =;  //should print out 0
i1 = str0.Compare("ab"); i1 =;  //should print out 1
i2 = str0.Compare("xyz"); i2 =;  //should print out -1
i3 = str0.Compare("IjK"); i3 =;  //should print out 1

CompareNoCase

This function performs a non case-insensitive comparison of this string object with another string.

Syntax

int nRet = str.CompareNoCase(str2$);

Return

0 if the strings are identical, < 0 if this string object is less than str2$ in the dictionary order, or > 0 if this string object is greater than str2$.

Examples

string str0$ = "ijk";
i0 = str0.CompareNoCase("ijk"); i0 =;  //should print out 0
i1 = str0.CompareNoCase("ab"); i1 =;  //should print out 1
i2 = str0.CompareNoCase("xyz"); i2 =;  //should print out -1
i3 = str0.CompareNoCase("IjK"); i3 =;  //should print out 0

Count

Count number of occurances of specified charactor (in case-sensitive way) in the string. This function supports wildcard characters.

Syntax

int nRet = str.Count(ch);

Return

Number of times given character appears in string

Examples

string str$ = "this is a test";
i=str.Count(' '); i=; //should print out 3
i=str.Count('x'); i=; //should print out 0

Delete

Deletes a character or characters from a string starting with the character at index. If count is longer than the string, the remainder of the string will be removed.

Syntax

int nRet = str.Delete(index, count = 1 );

Return

The length of the changed string.

Examples

string str$ = "this is a test";
i=str.Delete(3); 
i=; //should print out 13
str$=; //should print out ths is a test
i=str.Delete(3, 2);
i=; //should print out 11
str$=; //should print out this a test

Empty

Makes this string object an empty string (0 length) and frees memory as appropriate.

Syntax

int nRet = str.Empty();

SeeAlso

IsEmpty

Examples

string str$="abc";
i=str.GetLength( ); i=; //should return 3
str.Empty();
i=str.GetLength( ); i=; //should return 0

EnvVar

This function returns the string value stored in the corresponding Windows environment variable, which is stored in this string. Note: if this string is not a valid Windows environment variable string, there will be error.

Syntax

string str1$ = str.EnvVar()$;

Return

The string value stored in the Windows environment variable.

Examples

string str$ = "computername";
string str1$ = str.EnvVar()$;
str1$ = ;  // The computer name of local machine
str$ = "appdata";
str1$ = str.EnvVar()$;
str1$ = ;  // The directory path to the Application Data folder

Exact

Test whether a string matches (has the same contents and length) another string.

Syntax

int nRet = str.Exact(str2$);

Return

If matched, return 1, otherwise, return 0.

SeeAlso

Compare

Examples

string str1$ = "ijk";
string str2$ = "IJK";
string str3$ = "abc";
string str4$ = "ijk";
i1 = str1.exact(str2$);  // i1 = 0
i2 = str1.exact(str3$);  // i2 = 0
i3 = str1.exact(str4$);  // i3 = 1

Find

Find the character index (from the beginning character, default from the first character) in the string. Find is case sensitive. Find does not allow wildcard characters.

Syntax

int nRet = str.Find(str2$[,offset]);

Return

The 1-based index of the first character if found or 0 if there is no match.

See Also

FindOneOf, GetToken

Examples

string str$="Today is a nice day";
i=str.Find(',');
i=;  // should print 0 since comma(,) cannot be found
i=str.Find('a');
i=;  // should print 4 as that is the first "a" in the string
// can also find a substring
i = str.Find("is");
i =;  // should print 7 as the offset of that substring
//find 2nd occurance
i = str.Find('a', 7);// find starting from "is a ..."
i =;  // should print 10

FindOneOf

This member function searches this string for the first character that is also in the specified string.

Syntax

int nRet = str.FindOneOf(arg$);

Return

The one-based index of the first character if found or 0 if there is no match.

SeeAlso

Find

Examples

string str$="abcdef";
i=str.FindOneOf("xd");
i=; //should print out 4 as 'd' is first match
i=str.FindOneOf("xyz");
i=; // should print 0

FindToken

Find a token in the string, if chDelimiter not specified, default to white spaces.

Syntax

int nRet = str.FindToken(aToken$, chDelimiter)

Return

The index of the token if found, 0 if token was not found

SeeAlso

GetNumTokens, GetToken

Examples

str$="sss abc def abc xyz abc";
i=str.FindToken("abc");
i=;  //should print out 2

Format

This method first will try to convert the string in a double value, and then convert this double value to string with a LabTalk formatting option. If the string is not able to be converted into a double value, missing value will be returned.

The parameter is a string specifying the number of significant figures to convert. The value is the empty string, "", which will use @SD significant digits, where @SD is a system variable (whose current value can be obtained by entering @SD= in the Scripting Window). The value "*3" for the string fmt$ will yield 3 significant digits in the returned string. Use "*" to use Origin's global setting.

Syntax

string str1$ = str.Format(fmt$)$;

Return

The numeric data as a string with the specified number of significant figures. If the string is not a numeric-data-like string, return missing value.

Examples

string str$ = "2.01232";
string str1$ = str.Format("*3")$;  // 3 significant figures
str1$ = ;  // Should be 2.01

@SD = ;  // Get the current value stored in @SD system variable
@SD = 2;  // Set the value in @SD to 2
str$ = "2.456789";
str1$ = str.Format("")$;  // Use the system default, @SD
str1$ = ;  // Should be 2.5

FromFile

This member function loads string from text file.

Syntax

int nRet = str.FromFile(arg$);

Return

1 for success, 0 for failure

Examples

dlgfile g:=*.ogs; //pick a file and fname$ will keep the file name
string str$;
i = str.FromFile(fname$);//file content will be in str$
i =; //1 for success

GetAt

Returns a single character specified by an index number.

Syntax

int ch = str.GetAt(index)

Return

A char containing the character at the specified position in the string.

SeeAlso

SetAt

Examples

str$="sss abc def abc xyz abc";
i=str.GetAt(5);
i=;  //should print out 97, a's ASCII code

GetFileExt

Get the file extension from the full path.

Syntax

 string str = GetFileExt()$ ;

SeeAlso

IsFile, IsPath, GetFilePath, GetFilename

Return

return the file extension or empty string if not a file name.

Examples

fname$=%Y; // user file folder path
fname$+= "origin.ini";
if(fname.IsFile()) // origin.ini existed in the user files folder
{
   string strExt$=fname.GetFileExt()$;
   strExt$=; // should print ini
}
else
   type "origin.ini not found";

GetFileName

Get the file name (with or without the extension) from the full path. If bRemoveExt is not specified, then file extension is kept.

Syntax

string str = GetFileName(bRemoveExt])$

SeeAlso

IsFile, IsPath, GetFileExt, GetFilePath

Return

the file name without extension if bRemoveExt = 1, else with file extension.

Examples

strpath$="%Yorigin.ini";// user path there is always this file

fname$ = strpath.GetFileName()$; // return empty string if file path only                             
// and no file name
fname$=;// should print "origin.ini" 
str2$=strpath.GetFileName(1)$;
str2$=;// should print just "origin"

GetFilePath

Get the path from the full path.

Syntax

string str = GetFilePath()$;

Return

The full file path

SeeAlso

IsFile, IsPath, GetFileExt, GetFileName

Examples

str.IsFile();
fname$ = str.GetFilePath()$; // return empty string if no path found

GetLength

Get the length of a string.

Syntax

int nLen = str.GetLength();

Return

the string length, return 0 if string is empty

Examples

string str$ = " abc "; // string with both leading and trailing spaces
i = str.GetLength();
i =; //should print out 5

GetNumTokens

This function returns the number of tokens in the string where a token is separated by the delimiter specified by chDelimiter. When chDelimiter was not specified, any white space (space, tab, newline, etc.) is to be used as the delimiter.

Syntax

int nRet = str.GetNumTokens(chDelimiter);

Return

The number of tokens in this string.

SeeAlso

GetToken, FindToken

Examples

string str1$="apples peaches pumpkins";
string str2$="apples,peaches,pumpkins";
i1=str1.GetNumTokens(); 
i1=;  // should print out 3
i2=str2.GetNumTokens(','); 
i2=;  // should print out 3

GetToken

This function returns the nth token where a token is separated by the delimiter specified by chDelimiter. The chDelimiter can be a character quoted by double quotation marks or a LabTalk Keyword. When chDelimiter was not specified or invalid, any white space (space, tab, newline, etc.) is to be used as the delimiter.

Syntax

string strToken$ = str.GetToken(int n, chDelimiter)$;

Return

The extracted string token.

SeeAlso

GetNumTokens, FindToken

Examples

aaa$="Boston DC LA";
//Note $ sign at end, because GetToken returns a string
bbb$=aaa.GetToken(2)$;  
bbb$=;// print DC

aaa$="srtA%(TAB)strAA%(TAB)strAAA";  //-- there are 2 tabs in this string
bbb$=aaa.GetToken(2, TAB)$;
bbb$=; // print strAA

Please note the use of LabTalk Keywords TAB in the example above.

Here is another example showing the use of CRLF

dlgfile g:="*.png;*.jpg" m:=1 init:=system.path.program$+"Samples\Image Processing and Analysis";
int nn = fname.GetNumTokens(CRLF);//number of files
for(i=1;i<=nn;i++)
{
        string strFile$ = fname.GetToken(i, CRLF)$;
        type "File$(i)%(CRLF)%(strFile$)";
}

Insert

This function inserts a substring at the given index within the string. The nIndex parameter identifies the first character that will be moved to make room for the substring. If nIndex is zero, the insertion will occur before the entire string. If nIndex is higher than the length of the string, the function will concatenate the string and the substring.

Syntax

int nRet = str.Insert(nIndex, str$);

Return

The length of the changed string.

SeeAlso

Delete

Examples

ss$="I summer";
ss.Insert(3,"love ");
ss$=;  // should print out "I love summer"

IsEmpty

Test whether a string is empty or not.

Syntax

int nRet = str.IsEmpty();

Return

1 if the string is empty; otherwise 0.

SeeAlso

Empty, GetLength

Examples

string str;  //initial empty string;
str$="abc";   
i=str.IsEmpty();
i=; //should print out 0

str.Empty();  //empty the string
i=str.IsEmpty();i=; //sholuld print out 1

IsFile

This member function test whether the string is a valid full path file name

Syntax

int nRet = str.IsFile(arg$);

Return

Return 1 if the string is a filename that exist, else return 0.

SeeAlso

GetFileName, GetFileExt, IsPath

Examples

strFile$="%Yorigin.ini";
i=strFile.IsFile(); 
i=; // should print out 1 since this file is always there

strFile$="%Yorigin.dll";
i=strFile.IsFile(); 
i=; // should print out 0 since there should not be such a file

IsPath

Test whether the string is a valid file path.

Syntax

int nRet = str.IsPath( )

Return

Return 1 if the string is "filepath", else return 0.

SeeAlso

GetFileName, GetFileExt

Examples

ss$="c:\";
i=ss.IsPath(); i=; //should print out 1 (as C: drive exists)
ss$=system.path.program$;
i=ss.IsPath(); i=; //should print out 1
ss$=ss$+"junk\";
// should print 0 as there should not be such a file folder
i=ss.IsPath(); i=;

Left

Extracts the first nCount characters from this string and returns the extracted substring. If nCount exceeds the string length, then the entire string is extracted.

The behavior of this method has changed from that of Origin Version 8.0 SR5 and previous versions, in which str.Left(n) returned the left-most n - 1 characters in the string. The change represents an effort to align our methods with general string handling convention and prevent confusion for new users. The second example below illustrates both old and new behavior.

Syntax

string str2$ = str1.Left(nCount)$;

Return

A string containing the specified range of characters. Note that the returned string may be empty.

SeeAlso

Right, Mid

Examples

string str1$="I love summer!";
str2$=str1.left(6)$; str2$=;  // should print out "I love"
str3$=str1.left(100)$; str3$=;  // should print out "I love summer!"

The example below demonstrates the version-specific behavior of str.Left():

string str1,str2;
str1$ = This is a Test;

// Let's say we want str2$ to contain the string "This" ...

// @V is a system variable that stores the current version of Origin @V 
// 8.0987 = SR5 = Last version  which returned n-1 characters
if (> 8.0987) str2$ = str1.left(4)$;     
// if you use Origin Version 8.0 SR5 or earlier,
// enter n+1 in order to return n characters                                          
else str2$ = str1.left(5)$;             
str2$=;                                   // "This"

Len

Return the length of a string.

Syntax

int nLen = str.Len();

Return

The length of string, if the string is empty, return 0.

SeeAlso

GetLength

Examples

string str$ = " abc "; // string with both leading and trailing spaces
i = str.Len();
i =; // should print out 5

Lower

Return the lowercase string of the string.

Syntax

string str1$ = str.Lower()$;

Return

Lowercase string of this string.

SeeAlso

Upper, MakeLower

Examples

string str$="ABCD=123+xyz";
string str1$ = str.Lower()$; 
str1$ = ;  // should return "abcd=123+xyz"

MakeCSV

This function generates a string which has a delimiter into CSV format.

Syntax

string str1$ = str.MakeCSV(nQuote, nValSep[, srcDelimiter$])$;
  • nQuote specifies what quote to add. The default value 0 means do not add quote. 1 means single quote (') and 2 means double quote (").
  • nValSep specifies the delimiter in the CSV formatted string. Default value 0 means comma separator (,) and 1 means semicolon separator (;).
  • srcDelimiter$ specifies the delimiter in the source string. Not needed if delimiter is white space: <space>, <tab>, <carriage return>, <line feed>.

Return

CSV formatted string.

Examples

string str$ = "This is test value";
string str1$ = str.MakeCSV(2, 1)$;
str1$ = ;  // Should be "This";"is";"test";"value"

str$ = "This|is|test|value";
str1$ = str.MakeCSV(1, 0, "|")$;  // Source delimiter is |
str1$ = ;  // Should be 'This','is','test','value'

MakeLower

Convert this string to a lowercase string.

Syntax

str.MakeLower();

SeeAlso

MakeUpper

Examples

string str$="ABCD=123+xyz";
str.MakeLower(); 
str$=;  // should return "abcd=123+xyz"

MakeUpper

Convert this string object to a uppercase string.

Syntax

str.MakeUpper();

SeeAlso

MakeLower

Examples

string str$="ABC=123+xyz";
str.MakeUpper(); 
str$=;  // should return "ABC=123+XYZ"

Match

String pattern matching, any number of wild card characters are supported, which can be *(any string) or ? (any one character). Also, matching with or without case-sensitivity is supported. If bCaseSensitive is not specified, default is case insensitive.

Syntax

int nRet = str.Match( strPattern$, bCaseSensitive);

Return

Return 1 if the provided pattern matches the string, else 0 if not matched.

Examples

string str$ = "abcdefg";

i=str.Match("ab*");
i=; // should print out 1

i=str.Match("?*e*f?");
i=; // should print out 1

i=str.Match("abcDEFG");
i=; // should print out 1 (case insensitive)

i=str.Match("abcDEFG", 1);
i=; // should print out 0 (case sensitive)

MatchBegin

This method finds a string pattern (str1$) from the specified position m, and returns an integer corresponding to the starting position of the pattern in the string. This function allows the wildcard characters * and ?. To search for literal * or ?, use Search as it does not support wildcards.

Syntax

int pos = str.MatchBegin(str1$[, m, n]);
  • str1$ is the pattern string.
  • m is the starting position to search. This is optional, if not specified, start from the first position.
  • n is optional parameter to specify if case sensitive. Default value is 0, which is not case sensitive, and 1 for case sensitive.

Return

The starting position of the string pattern found in the string, if the string pattern has not been found, return -1.

SeeAlso

MatchEnd

Examples

string str$ = "From: test@Originlab.com";
string str1$ = "From*@";
int position = str.MatchBegin(str1$, 1);
position = ;  // Should return 1
string str$ = "search inside this string";
string str1$ = "?in";
int position = str.MatchBegin(str1$); 
position = ;  // Should return 8 as position of first non-wildcard character

MatchEnd

This method finds a string pattern (str1$) from the specified position m, and returns an integer corresponding to the ending position of the pattern in the string. This function allows the wildcard characters * and ?. When using wildcards, MatchEnd returns the index for the first non-wildcard character. To search for raw characters, * or ?, use the Search function (which does not support wildcard characters).

Syntax

int pos = str.MatchEnd(str1$[, m, n]);
  • str1$ is the pattern string.
  • m is the starting position to search. This is optional, if not specified, start from the first position.
  • n is optional parameter to specify if case sensitive. Default value is 0, which is not case sensitive, and 1 for case sensitive.

Return

The ending position of the string pattern found in the string, if the string pattern has not been found, return -1.

SeeAlso

MatchBegin.

Examples

string str$ = "From: test@Originlab.com";
string str1$ = "From*@";
int position = str.MatchEnd(str1$);
position = ;  // Should return 11

Mid

Extracts a substring of length nCount (or up to the end of the string if omitted) characters starting at position nFirst from the string.

The behavior of this method has changed from that of Origin Version 8.0 SR4 and previous versions, in which str.Mid(m,n) returned the n - 1 characters in the string, starting at position m. The change represents an effort to align our methods with general string handling convention and prevent confusion for new users. The second example below illustrates both old and new behavior.


Syntax

string strMid = str.Mid(nFirst, nCount)$;

Return

Returns a copy of the extracted substring.

SeeAlso

Left, Right

Examples

string str1$="I love summer!";

str2$=str1.mid(3)$; 
str2$=; // should return "love summer!"

str3$=str1.mid(3,4)$; 
str3$=; // should return "love"

The example below demonstrates the version-specific behavior of str.Mid():

string str1,str2;
str1$ = This is a Test;

// Let's say we want str2$ to contain the string "is" ...
// @V is a system variable that stores the current version of Origin 
// 8.0951 = SR4 = Last version which returned n-1 characters
if (@V > 8.0951) str2$ = str1.mid(6,2)$;    
// if you use Origin Version 8.0 SR4 or earlier,  
// enter n+1 in order to return n characters                                
else str2$ = str1.mid(6,3)$;              
str2$=;                                    // "is"

Remove

This member function removes instances of ch from the string. Comparisons for the character are case-sensitive.

Syntax

int nRet = str.Remove(ch);

Return

The count of characters removed from the string. Zero if the string isn't changed.

SeeAlso

Replace

Examples

string str$="apple";
str.Remove('p');
str$=;  //should print out "ale"

Replace

This function replaces instances of patternstr$ with the string or character strNew$. An already-replaced partial string containing patternstr$ is no longer used for the matching process.

Syntax

int nRet = str.Replace(patternstr$, strNew$ )

Return

The number of replaced instances of the strNew$. Zero if no replacement took place.

Examples

string str = "user       www.abc.com";

int nRet1 = str.Replace('%(TAB)', '@');
// Replace with char
str.Replace('%(TAB)', '@');
ty str$; // Output user@www.abc.com
nRet1=; // 1 instance of replacement

int nRet2 = str.Replace("www", "mail");
// Replace with string
str.Replace("www", "mail");
ty str$; // Output user@mail.abc.com
nRet2=; // 1 instance of replacement

ReverseFind

This function searches the string for the last match of a character.

Syntax

int nRet = str.ReverseFind(arg$);

Return

Returns the index(1-base) of the last character in this string object that matches the requested character; 0 if the character is not found.

SeeAlso

Find, FindOneOf, FindToken, GetToken

Examples

str$="abcabc";
i=str.ReverseFind('b'); 
i=;  //should print out 5

string str$="This island is nice.";
i=str.ReverseFind(','); 
i=;  // should print 0 since comma(,) cannot be found

i=str.ReverseFind('a'); 
i=;  // should print 9 as that is the last "a" in the string

i=str.ReverseFind("is"); 
i=;  //can also find a substring, should print 13 for the second "is"

Right

Extracts the rightmost nCount characters from this string and returns the extracted substring. If nCount exceeds the string length, then the entire string is extracted.

The behavior of this method has changed from that of Origin Version 8.0 SR5 and previous versions, in which str.Right(n) returned the right-most n - 1 characters in the string. The change represents an effort to align our methods with general string handling convention and prevent confusion for new users. The second example below illustrates both old and new behavior.

Syntax

string str2 = str.Right(nCount)$;

Return

A string containing the specified range of characters. Note that the returned string may be empty.

SeeAlso

Left, Mid

Examples

string str1$="I love summer!";
str2$=str1.right(4)$; 
str2$=;  // should print out "mer!"
str3$=str1.right(100)$; 
str3$=;  // should print out "I love summer!"

The example below demonstrates the version-specific behavior of str.Right():

string str1,str2;
str1$ = This is a Test;

// Let's say we want str2$ to contain the string "Test" ...
// @V is a system variable that stores the current version of Origin 
// 8.0987 = SR5 = Last version which returned n-1 characters
if (@V > 8.0987) str2$ = str1.right(4)$;    
// if you use Origin Version 8.0 SR5 or earlier,                                            
// enter n+1 in order to return n characters
else str2$ = str1.right(5)$;                
str2$=;                             // "Test"

Search

Finds a string (str1) from the specific position (nStartPos), and returns the starting position of str1 in the string. This function is not case sensitive and does not allow wildcard characters.

Syntax

int pos = str.Search(str1$[, nStartPos]);
  • str1$ is the string to search.
  • nStartPos is the starting position in the string to search. If not specified, the default value 1 is used.

Return

If the string has been found, return the position of the string. If the string has not been found, return -1.

SeeAlso

Find, MatchBegin

Examples

string str$ = "abcde";
string str1$ = "BC";
int pos = str.Search(str1$);
pos = ;  // Should return 2

SetAt

Overwrites a single character specified by an index number. SetAt will not enlarge the string if the index exceeds the bounds of the existing string.

Syntax

str.SetAt(nPos, ch);

SeeAlso

GetAt

Examples

string str1$="I love summer!";
str1.SetAt(1, 'W');
str1$=; //should print out W love summer!

SpanExcluding

Searches the string for the first occurrence of any character in the specified set strarg. SpanExcluding extracts and returns all characters preceding the first occurrence of a character from strarg(in other words, the character from strargand all characters following it in the string, are not returned). If no character from strarg is found in the string, then SpanExcluding returns the entire string.

Syntax

str2 = str.SpanExcluding(strarg$)$;

Return

A substring that contains characters in the string that are not in strarg, starting with the first character in the string and up to but excluding the first character in the string that is found strarg). It returns the entire string if no character in strarg is found in the string.

SeeAlso

SpanIncluding

Examples

string str1$= "Hello World! Goodbye!";
string str2$= ".!?";
str3$= str1.SpanExcluding(".!?")$; 
str3$= ; //should print out Hello World
//Notes: it is best to pass a string variable into this method,
//because in Labtalk method, string will always pass as Uppercase,
//but this method is case sensitive.

SpanIncluding

Extracts characters from the string, starting with the first character, that are in the set of characters identified by strarg$. If the first character of the string is not in the character set, then SpanIncluding returns an empty string. Otherwise, it returns a sequence of consecutive characters which are in the set.

Syntax

str2 = str.SpanIncluding(strarg$)$;

Return

A substring that contains characters in the string that are in strarg, beginning with the first character in the string and ending when a character is found in the string that is not in strarg. SpanIncluding returns an empty substring if the first character in the string is not in the specified set.

SeeAlso

SpanExcluding

Examples

string str1$= "cabinet";
string str2$= "abc";
//Notes: it is best to pass a string variable into this method,
//because in Labtalk method, string will always pass as Uppercase,
//but this method is case sensitive.
str3$= str1.SpanIncluding(str2$)$; 
str3$=  ;//should print out cab

Substitute

This method finds the specified string (str3$) and then replace it with another string (str2$) if str3$ is found.

Syntax

string str1$ = str.Substitute(str2$, str3$[, n])$;
  • str2$ is the string to replace str3$.
  • str3$ is the string to be searched in this string.
  • n is optional. If 0 (default), all found str3$ will be replaced by str2$, otherwise, the specified nth found string is replaced.

Return

The new string after replace.

SeeAlso

Replace

Examples

string str$ = "abcdefabcdef";
string str1$ = str.Substitute("12", "bcd", 0)$;
str1$ = ; // Should return a new string: "a12efa12ef".

Token

This function returns the nth token where a token is separated by the delimiter specified by chDelimiter. The chDelimiter can be a character quoted by single or double quotation marks or a LabTalk Keyword. When chDelimiter was not specified, white space is to be used as the delimiter.

Syntax

string str1$ = str.Token(n, [chDelimiter])$;

Return

The extracted string token.

SeeAlso

GetToken

Examples

string str$="Boston DC LA";
string str1$ = str.Token(2)$;  
str1$ = ;  // Print DC
str$ = "srtA%(TAB)strAA%(TAB)strAAA";  // There are 2 tabs in this string
str1$ = str.Token(2, TAB)$;
str1$ = ;  // Print strAA
str$ = "Apple|Orange|Cherry";
str1$ = str.Token(3, '|')$;
str1$ = ;  // Print Cherry

Trim

Remove white space from the beginning and ending of the string, or remove all white space from the string, including those inside the string.

Syntax

string str1$ = str.Trim([option])$;

Return

By default, option is 0, and return a string removed white space from the beginning and ending of this string, if option is 1,

return a string removed all white space of this string, including the ones inside this string.

SeeAlso

TrimLeft, TrimRight

Examples

string str$ = "   I love summer!   ";
str.GetLength() = ;  // 20
string str1$ = str.Trim()$;
str1.GetLength() = ;  // 14
str1$ = ;  // I love summer!
string str2$ = str1.Trim(1)$;
str2.GetLength() = ;  // 12
str2$ = ;  // Ilovesummer!

TrimLeft

Remove a group of particular characters from the begining of the string.It removes leading newline, space, and tab characters from the source string by default.

Syntax

str.TrimLeft( [arg$] );

SeeAlso

TrimRight

Examples

string str1$="   I love summer!";
i = str1.GetLength();
i =; //should print out 17 
str1.TrimLeft();
i = str1.GetLength();
i =; //should print out 14
str1.TrimLeft("I love");
i = str1.GetLength();
i =; //should print out 7

TrimRight

Remove a group of particular characters from the ending of the string.It removes the end newline, space, and tab characters from the source string by default.

Syntax

str.TrimRight();

SeeAlso

TrimLeft

Examples

string str1$="I love summer!   ";
i = str1.GetLength();
i =; //should print out 17 
str1.TrimRight();
i = str1.GetLength();
i =; //should print out 14
str1.TrimRight(" summer!");
str1$=; //return "I lov"

Upper

Return the uppercase string of the string.

Syntax

string str1$ = str.Upper()$;

Return

Uppercase string of this string.

SeeAlso

Lower, MakeUpper

Examples

string str$="ABCD=123+xyz";
string str1$ = str.Upper()$; 
str1$ = ;  // should return "ABCD=123+XYZ"

Value

Parse the string as a numeric, and the leading and tailing white space will be trimmed.

Syntax

double dValue = str.Value();

Return

Value parsed from the string, if the string is not able to parse as a numeric, return missing value.

Examples

string str$ = "  256.2   ";
double dV1 = str.Value();
dV1 = ;  // Should be 256.2
string str1$ = "5.2e-5";
double dV2 = str1.Value();
dV2 = ;  // Should be 5.2E-5
string str2$ = "1.2A";
double dV3 = str2.Value();
dV3 = ;  // Should be --