# String Functions

Jump to navigation
Jump to search

**Navigation: PGM SITEMAP**

Defining a Class | Defining a Function | Mathematical Functions | Defining a Subroutine | Tag Functions |
---|---|---|---|---|

Predefined Classes | Predefined Functions | String Functions | Trigger Subroutines | Example PGM Files |

The following routines are to be used exclusively for the manipulation of String (or STR) variables. All the routines' names are case insensitive.

See Also: String Function Examples
String Functions | ||||

Function |
Syntax |
Description
| ||
---|---|---|---|---|

ConcatenateReplaces the StrCat commands. |
variable = Concatenate(s1, s2, ...) Function returns a STRING |
Can combine any number of strings.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 orginal strings.
| ||

StrCatString Concatenate |
variable = StrCat(s1, s2) variable = StrCat2(s1, s2, s3) variable = StrCat3(s1, s2, s3, s4) variable = StrCat4(s1, s2, s3, s4, s5) variable = StrCat5(s1, s2, s3, s4, s5, s6) Function returns a STRING |
RECOMMEND USING Concatenate INSTEAD of StrCat. 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. StrCat appends s2 to s1 and assigns the result to variable, without altering either s1 or s2
StrCat2, StrCat3, StrCat4 and StrCat5 are similar to StrCat except that more strings can be appended simultaneously. | ||

StrStr String Search |
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.
| ||

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. | ||

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: the comparison is NOT case sensitive
| ||

LeftString 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.
| ||

RightString 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.
| ||

MidString 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.
| ||

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 stringNote: 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
| ||

IntToStrInteger to String |
variable = IntToStr(Integer) Function returns a STRING |
An integer to string conversion routine with no number formatting options. | ||

IntStrInteger 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.
| ||

IntStr0Integer 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).
| ||

FltToStrReal 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
| ||

FltStrReal 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.
| ||

StrToIntString to Integer |
variable = StrToInt(String) Function returns an integer |
A string to integer conversion routine | ||

StrToFltString to Real Number |
variable = StrToFlt(String) Function returns a Real Number |
A string to floating point number conversion routine | ||

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.
| ||

AlphaToNumString 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. | ||

NumToAlphaInteger 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. This function is only available in SysCAD 9.3 or later. | ||

IsAlphastring test function |
variable = IsAlpha(String) Function returns True or False |
Return true if ALL letters of string are alphabetic. | ||

IsEmptystring test function |
variable = IsEmpty(String) Function returns True or False |
Return true if string is empty or only contains a single space. |

## String Function Examples

Examples of all the string (STR) manipulation functions. STRING a, b, s, x, r, p@ LONG w@ REAL z@ CONST LONG q = 56 BIT [email protected], [email protected] 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 = strstr(s,"Cad") ;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) 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 = TrimWhiteSpace(x) ;r = "SysCAD 9.3" r = Trim(x, "2 .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 $