String Functions
(Redirected from PGM String Functions)
Jump to navigation
Jump to search
Navigation: PGMs ➔ Functions ➔ String Functions
Functions | Subroutines | Classes | |||||
---|---|---|---|---|---|---|---|
Defining a Function | Predefined Functions | Tag Functions | Mathematical Functions | String Functions | Defining a Subroutine | Trigger Subroutines | Defining a Class |
The following routines are to be used exclusively for the manipulation of String (or STR) variables. All the routines' names are case insensitive.
String Functions See Also: String Function Examples | ||||
Function | Syntax | Description | ||
---|---|---|---|---|
Concatenate String Concatenate |
variable = Concatenate(s1, s2, ...) Function returns a STRING |
Can combine a variable number of strings (minimum of 2, maximum of 20). s1, s2, s3, .... can either be pre-assigned variables of type String or a series of characters enclosed in double quotation marks. Concatenate appends s2 to s1 to s3 etc. and assigns the result to variable, without altering s1, s2, s3 or any of the original strings. | ||
StrCat String Concatenate |
variable = StrCat(s1, s2, ...) Function returns a STRING |
Equivalent to Concatenate function. Can combine a variable number of strings (minimum of 2, maximum of 20). s1, s2, s3, .... can either be pre-assigned variables of type String or a series of characters enclosed in double quotation marks. StrCat appends s2 to s1 to s3 etc. and assigns the result to variable, without altering s1, s2, s3 or any of the original strings. | ||
StrCat2, StrCat3... String Concatenate |
|
RECOMMEND USING Concatenate or StrCat INSTEAD of StrCat2, StrCat3, StrCat4 or StrCat5. s1, s2, s3, s4, s5 and s6 can either be a pre-assigned variable of type STR or a series of characters enclosed in double quotation marks. Combines the sting parameters and assigns the result to variable, without altering either s1, s2, s3, etc. StrCat2, StrCat3, StrCat4 and StrCat5 require exactly the correct number of parameters. | ||
StrStr String Search Equivalent to StrFind |
variable = StrStr(string1, string2) Function returns an Integer value |
StrStr searches string1, from left to right, for the first occurrence of string2. If successful, then the zero-based index of the first character of string2 within string1 is assigned to variable. If unsuccessful then -1 is assigned to variable. Note: the search is case sensitive. | ||
StrFind String Search Equivalent to StrStr |
variable = StrFind(string1, string2) Function returns an Integer value |
StrFind searches string1, from left to right, for the first occurrence of string2. If successful, then the zero-based index of the first character of string2 within string1 is assigned to variable. If unsuccessful then -1 is assigned to variable. Note: the search is case sensitive. Available from Build 139.32082. | ||
StrStrFrom String Search Equivalent to StrFindFrom |
variable = StrStrFrom(string1, string2, FromIndex) Function returns an Integer value |
StrStrFrom searches string1, from position FromIndex (zero based index), for the first occurrence of string2 . If successful, then the zero-based index of the first character of string2 within string1 is assigned to variable. If unsuccessful then -1 is assigned to variable. Note: the search is case sensitive. Available from Build 139.31602. | ||
StrFindFrom String Search Equivalent to StrStrFrom |
variable = StrFindFrom(string1, string2, FromIndex) Function returns an Integer value |
StrFindFrom searches string1, from position FromIndex (zero based index), for the first occurrence of string2 . If successful, then the zero-based index of the first character of string2 within string1 is assigned to variable. If unsuccessful then -1 is assigned to variable. Note: the search is case sensitive. Available from Build 139.32082. | ||
StrCmp String Comparison Case Sensitive |
variable = StrCmp(string1, string2) Function returns an Integer value |
StrCmp compares string1 to string2. If string1 is less than string2 the resultant value of variable is less than zero. If string1 is equal to string2 the resultant value of variable is zero. If string1 is greater than string2 the resultant value of variable is greater than zero. Note: This comparison IS case sensitive. Note: The greater/less than comparison refers to the first non-matching character's ASCII value. | ||
StriCmp String Comparison Case Insensitive |
variable = StriCmp (string1, string2) Function returns an Integer value |
StriCmp compares string1 to string2. If string1 is less than string2 the resultant value of variable is less than zero. If string1 is equal to string2 the resultant value of variable is zero. If string1 is greater than string2 the resultant value of variable is greater than zero. Note: This comparison IS NOT case sensitive. Note: The greater/less than comparison refers to the first non-matching character's ASCII value. | ||
Left String Extraction |
variable = Left(string, n) Function returns a STRING |
Left extracts the specified number of characters, n, from the left side of string and assigns the result to variable, without altering string. Note: if n exceeds the string length, then string is assigned to variable. | ||
Right String Extraction |
variable = Right(string, n) Function returns a STRING |
Right extracts the specified number of characters, n, from the right side of string and assigns the result to variable, without altering string. Note: if n exceeds the string length, then string is assigned to variable. | ||
Mid String Extraction |
variable = Mid(string, start, n) Function returns a STRING |
Mid extracts the specified number of characters, n, beginning at the position within string specified by start and assigns the result to variable, without altering string. Note: If n, due to the position of start, exceeds the string length, then n is truncated accordingly. If start exceeds the string length, then the value of NULL is assigned to variable. | ||
StrErase String Extraction |
variable = StrErase(string, StartIndex, n) Function returns a STRING |
StrErase removes the specified number of characters, n, from string starting from the StartIndex and assigns the result to variable, without altering string. Note: StrErase(s1, 5, 9999) is the same is Left(s1, 5) assuming s1 length < (9999+5) Available from Build 139.32082. | ||
StrInsert | variable = StrInsert(string, InsertString, StartIndex) Function returns a STRING |
StrInsert adds the InsertString to string starting from the StartIndex and assigns the result to variable, without altering string. Available from Build 139.32082. | ||
StrReplace | variable = StrReplace(string, SearchString, ReplaceString) Function returns a STRING |
StrReplace searches the string to find any occurrences of SearchString. If successful, then the SearchString is replaced with ReplaceString. Search string is case sensitive. Available from Build 139.32082. | ||
StrReplaceFrom | variable = StrReplaceFrom(string, SearchString, ReplaceString, FromIndex) Function returns a STRING |
StrReplaceFrom searches string from position FromIndex (zero based index), for any occurrences of SearchString. If successful, then the SearchString is replaced with ReplaceString. Search string is case sensitive. Available from Build 139.32082. | ||
StrLen String Length |
variable = StrLen(string) Function returns an Integer |
StrLen determines the size (number of characters contained within the string) of string and assigns the result to variable, without altering string Note: In some cases a 'blank' field may NOT return a length of zero (e.g. if the user has deleted a string). In this case, the user may use the command 'TrimWhiteSpace' to ensure that the field IS empty. | ||
StrUpr Convert to Upper Case |
variable = StrUpr(string) Function returns a STRING |
StrUpr converts all the characters of string to upper case and assigns the result to variable, without altering string | ||
StrLwr Convert to Lower Case |
variable = StrLwr(string) Function returns a STRING |
StrLwr converts all the characters of string to lower case and assigns the result to variable, without altering string | ||
IntToStr Integer to String |
variable = IntToStr(Integer) Function returns a STRING |
An integer to string conversion routine with no number formatting options. | ||
IntStr Integer to String |
variable = IntStr(Integer, length) Function returns a STRING |
An integer to string conversion routine, with number formatting options. IntStr converts integer to a string of the specified length and assigns the result to variable. Note: if integer is greater than length then the string is expanded to fit the number. If integer is less than length then the remaining characters are filled, from the left with blank spaces. | ||
IntStr0 Integer to String |
variable = IntStr0(Integer, length) Function returns a STRING |
An integer to string conversion routine, with number formatting options. IntStr0 converts integer to a string of the specified length and assigns the result to variable. Note: if integer is greater than length then the string is expanded to fit the number. If integer is less than length then the remaining characters are filled, from the left with 0 (zero). | ||
FltToStr Real number to String |
variable = FltToStr(fNumber) Function returns a STRING |
A floating point number to string conversion routine, with no number formatting options. fNumber: the number of type REAL or DOUBLE required to be converted to a string | ||
FltStr Real number to String |
variable = FltStr(fNumber, precision, length) Function returns a STRING |
FltStr converts a real number fnumber to a string of the specified length, with the specified precision and assigns the result to variable. Note: precision is the number of decimal places required after the decimal point If fnumber is greater than length then the string is expanded to fit the number. If fnumber is less than length then the remaining characters are filled, from the left with blank spaces. If precision, is less than the decimal numbers of fnumber, then the numbers are rounded off at the specified position. If precision is greater than the decimal numbers of fnumber, then the difference is filled with zeros. | ||
StrToInt String to Integer |
variable = StrToInt(String) Function returns an integer |
A string to integer conversion routine | ||
StrToFlt String to Real Number |
variable = StrToFlt(String) Function returns a Real Number |
A string to floating point number conversion routine | ||
ConstStr | variable = ConstStr(constant or enum) Function returns a STRING |
A constant of type real, integer, enum or enumdroplist is returned as a string of the constant variable name. For example ConstStr(PI) returns "PI". Available from Build 139.31388. | ||
EnumStr | variable = EnumStr(enumdroplist) Function returns a STRING |
A variable of type enumdroplist is returned as a string based on the current value of the EnumDropList variable parameter. Available from Build 139.31388. | ||
Trim | variable = Trim(string1, string2) Function returns a STRING |
A string trimming routine. Trim searches string1, at the start and the end for an occurrence of each character in string2. If any number of any of the characters in string2 is found in either of these 2 positions, then it is removed from string1 and the resulting string is stored in variable . Note: the function is case sensitive. | ||
TrimWhiteSpace | variable = TrimWhiteSpace(string1) Function returns a STRING |
TrimWhiteSpace searches the start and end of string1, for blank spaces. If any leading or trailing blank spaces are found they are removed from string1 and the resulting string is stored in variable. Note that a string that is visible and an input in the Access window will often have a single space, this is added automatically when editing the field or using the Access window. | ||
AlphaToNum String to Integer |
variable = AlphaToNum(String) Function returns an integer |
Based on first letter of string, returns 1 for 'a' or 'A'; 2 for 'b' or 'B' and so on. | ||
NumToAlpha Integer to String |
variable = NumToAlpha(integer) Function returns a STRING |
Based on number, returns upper case 'A' to 'Z' for 1 to 26; or lower case 'a' to 'z' for 27 to 52; otherwise returns empty string. | ||
IsAlpha string test function |
variable = IsAlpha(String) Function returns True or False |
Return true if ALL letters of string are alphabetic. | ||
IsEmpty string test function |
variable = IsEmpty(String) Function returns True or False |
Return true if string is empty or only contains a single space. | ||
iifStr() | Variable = iifStr(expression, truePart, falsePart) Function returns a STRING |
The iifStr function is a two part if() statement, based on the condition of the expression, the True or False string value (or string expression) is returned. Available from Build 139. See IIfStr for more detail. |
String Function Examples
Example 1
Examples of string manipulation functions.
STRING a, b, s, x, r, p@
LONG w@
REAL z@
CONST LONG q = 56
BIT All_Alphabetic@, EmptyString@
a = "Sys"
b = "CAD"
s = "SysCAD"
x = "SysCAD 9.3 "
z = 29.53
r = Concatenate(a,b) ;r = "SysCAD"
r = Concatenate(s," V9") ;r = "SysCAD V9"
r = Concatenate(a,b," V9") ;r = "SysCAD V9"
r = Concatenate(a,b," V9",".3") ;r = "SysCAD V9.3"
r = StrCat(a,b) ;r = "SysCAD"
r = StrCat(s," V9") ;r = "SysCAD V9"
r = StrCat2(a,b," V9") ;r = "SysCAD V9"
r = StrCat3(a,b," V9",".3") ;r = "SysCAD V9.3"
w = StrStr(s,b) ;w = 3
w = StrFind(s,b) ;w = 3
w = StrStr(s,"Cad") ;w = -1 (not found)
w = StrFind(s,"Cad") ;w = -1 (not found)
w = StrStrFrom(s,b,3) ;w = 3
w = StrFindFrom(s,b,3) ;w = 3
w = StrStrFrom(s,b,4) ;w = -1 (not found)
w = StrFindFrom(s,b,4) ;w = -1 (not found)
w = StrCmp(s,"syscad") ;w < 0
w = StrCmp(s,"SysCAD") ;w = 0
w = StriCmp(s,"syscad") ;w = 0
w = StriCmp(s,a) ;w > 0
r = Left(s,3) ;r = "Sys"
r = Left(s,12) ;r = "SysCAD"
r = Right(s,3) ;r = "CAD"
r = Right(s,12) ;r = "SysCAD"
r = Mid(s,2,3) ;r = "sCA"
r = Mid(s,3,255) ;r = "CAD"
r = Mid(s,9,2) ;r = "" (invalid index)
r = StrInsert(s, "Build139", 0) ;r = "Build139SysCAD"
r = StrInsert(s, "Build139", 6) ;r = "SysCADBuild139"
r = StrInsert(x, "Build139", 6) ;r = "SysCADBuild139 9.3"
r = StrErase(x, 4, 9999) ;r = "SysC"
r = StrReplace(x, "9.3", "Build139.32082") ;r = "SysCAD Build139.32082"
r = StrReplace(s, "S", "_X_") ;r = "_X_ysCAD" (case sensitive)
r = StrReplaceFrom(s, "s", "_Y_", 3) ;r = "SysCAD" (nothing to replace)
r = StrReplaceFrom(s, "s", "_Y_", 2) ;r = "Sy_Y_CAD" (case sensitive)
w = StrLen(s) ;w = 6
r = StrUpr(s) ;r = "SYSCAD"
r = StrLwr(s) ;r = "syscad"
r = IntStr(30565,4) ;r = "30565"
r = IntStr(Q,5) ;r = " 56" (56 has 3 spaces in front, thus having a length of 5)
r = IntStr0(Q,5) ;r = "00056" (56 has three zeros in front, thus having a length of 5).
r = FltStr(305.65,2,4) ;r = "305.65"
r = FltStr(56.453,4,10) ;r = " 56.4530" (added 3 spaces in front)
r = FltToStr(56.453) ;r = "56.453" (no formatting)
r = FltToStr(z) ;r = "29.53"
r = ConstStr(q) ;r = "q"
r = TrimWhiteSpace(x) ;r = "SysCAD 9.3"
r = Trim(x, "3 .9") ;r = "SysCAD"
w = AlphaToNum(a) ;w = 19
All_Alphabetic = IsAlpha(s) ;All_Alphabetic = 1
All_Alphabetic = IsAlpha(x) ;All_Alphabetic = 0
EmptyString = IsEmpty(p) ;EmptyString = 1
EmptyString = IsEmpty(x) ;EmptyString = 0
$
Example 2
iifStr Example (available in Build139 and later)
Checkbox Controller_On*
String Control_Status@
Control_Status = iifstr(Controller_On, "Control is Automatic", "Control is Manual")