This function extracts a substring using begin and end strings or characters.
Syntax
string str1$ = str.Between(str2$,str3$);
Return
SeeAlso
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"
This function returns the ASCII code for the first character of the string.
Syntax
int code = str.Code();
Return
Examples
string str$ = "ABC"; int code = str.Code(); // code = 65
This function performs a case-sensitive comparison of the string with another string.
Syntax
int nRet = str.Compare(str2$);
Return
SeeAlso
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
This function performs a case-insensitive comparison of this string object with another string.
Syntax
int nRet = str.CompareNoCase(str2$);
Return
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 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
Examples
string str$ = "this is a test"; i=str.Count(' '); i=; //should print out 3 i=str.Count('x'); i=; //should print out 0
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
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
Makes this string object an empty string (0 length) and frees memory as appropriate.
Syntax
int nRet = str.Empty();
SeeAlso
Examples
string str$="abc"; i=str.GetLength( ); i=; //should return 3 str.Empty(); i=str.GetLength( ); i=; //should return 0
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
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
Test whether a string matches (has the same contents and length) another string.
Syntax
int nRet = str.Exact(str2$);
Return
SeeAlso
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 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
See Also
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
This member function searches this string for the first character that is also in the specified string.
Syntax
int nRet = str.FindOneOf(arg$);
Return
SeeAlso
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
Find a token in the string, if chDelimiter not specified, default to white spaces.
Syntax
int nRet = str.FindToken(aToken$, chDelimiter)
Return
SeeAlso
Examples
str$="sss abc def abc xyz abc"; i=str.FindToken("abc"); i=; //should print out 2
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
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
Returns a single character specified by an index number.
Syntax
int ch = str.GetAt(index)
Return
SeeAlso
Examples
str$="sss abc def abc xyz abc"; i=str.GetAt(5); i=; //should print out 97, a's ASCII code
Get the file extension from the full path.
Syntax
string str = GetFileExt()$ ;
SeeAlso
Return
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";
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
Return
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"
Get the path from the full path.
Syntax
string str = GetFilePath()$;
Return
SeeAlso
Examples
str.IsFile(); fname$ = str.GetFilePath()$; // return empty string if no path found
Get the length of a string.
Syntax
int nLen = str.GetLength();
Return
Examples
string str$ = " abc "; // string with both leading and trailing spaces i = str.GetLength(); i =; //should print out 5
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
SeeAlso
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
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
SeeAlso
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$)"; }
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
SeeAlso
Examples
ss$="I summer"; ss.Insert(3,"love "); ss$=; // should print out "I love summer"
Test whether a string is empty or not.
Syntax
int nRet = str.IsEmpty();
Return
SeeAlso
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
This member function test whether the string is a valid full path file name
Syntax
int nRet = str.IsFile(arg$);
Return
SeeAlso
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
Test whether the string is a valid file path.
Syntax
int nRet = str.IsPath( );
Return
SeeAlso
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=;
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
SeeAlso
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"
Return the length of a string.
Syntax
int nLen = str.Len();
Return
SeeAlso
Examples
string str$ = " abc "; // string with both leading and trailing spaces i = str.Len(); i =; // should print out 5
Return the lowercase string of the string.
Syntax
string str1$ = str.Lower()$;
Return
SeeAlso
Examples
string str$="ABCD=123+xyz"; string str1$ = str.Lower()$; str1$ = ; // should return "abcd=123+xyz"
This function generates a string which has a delimiter into CSV format.
Syntax
string str1$ = str.MakeCSV(nQuote, nValSep[, srcDelimiter$])$;
Return
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'
Convert this string to a lowercase string.
Syntax
str.MakeLower();
SeeAlso
Examples
string str$="ABCD=123+xyz"; str.MakeLower(); str$=; // should return "abcd=123+xyz"
Convert this string object to a uppercase string.
Syntax
str.MakeUpper();
SeeAlso
Examples
string str$="ABC=123+xyz"; str.MakeUpper(); str$=; // should return "ABC=123+XYZ"
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
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)
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]);
Return
SeeAlso
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
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]);
Return
SeeAlso
Examples
string str$ = "From: test@Originlab.com"; string str1$ = "From*@"; int position = str.MatchEnd(str1$); position = ; // Should return 11
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
SeeAlso
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"
This member function removes instances of ch from the string. Comparisons for the character are case-sensitive.
Syntax
int nRet = str.Remove(ch);
Return
SeeAlso
Examples
string str$="apple"; str.Remove('p'); str$=; //should print out "ale"
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
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
This function searches the string for the last match of a character.
Syntax
int nRet = str.ReverseFind(arg$);
Return
SeeAlso
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"
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
SeeAlso
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"
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
SeeAlso
Examples
string str$ = "abcde"; string str1$ = "BC"; int pos = str.Search(str1$); pos = ; // Should return 2
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
Examples
string str1$="I love summer!"; str1.SetAt(1, 'W'); str1$=; //should print out W love summer!
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
SeeAlso
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.
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
SeeAlso
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
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])$;
Return
SeeAlso
Examples
string str$ = "abcdefabcdef"; string str1$ = str.Substitute("12", "bcd", 0)$; str1$ = ; // Should return a new string: "a12efa12ef".
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
SeeAlso
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
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
return a string removed all white space of this string, including the ones inside this string.
SeeAlso
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!
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
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
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
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"
Return the uppercase string of the string.
Syntax
string str1$ = str.Upper()$;
Return
SeeAlso
Examples
string str$="ABCD=123+xyz"; string str1$ = str.Upper()$; str1$ = ; // should return "ABCD=123+XYZ"
Parse the string as a numeric, and the leading and tailing white space will be trimmed.
Syntax
double dValue = str.Value();
Return
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 --