String Functions
From SysCAD Documentation
Navigation: PGMs
The following routines are to be used exclusively for the manipulation of STR variables. All the routines' names are case insensitive.
| String Functions See Also: String Function Examples | ||||
| Function | Syntax | Description | ||
|---|---|---|---|---|
| StrCat String 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 | 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 | ||
| 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. | ||
| 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 | ||
| 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. | ||
| 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 real number of type 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 | ||
| 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 string2. If 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 search 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 . | ||
String Function Examples
Examples of all the string (STR) manipulation functions. STR a, b, s, r* LONG w* CONST LONG q = 56 a = "Sys" b = "CAD" s = "SysCAD" x = " SysCAD 9.2" 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",".1") ;r = "SysCAD V9.1" 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 = fltstr(305.65,2,4) ;r = "305.65" r = fltstr(56.453,4,10) ;r = " 56.4530" (added 3 spaces in front) r = Trim(x, 9.2) ;r = " SysCAD " r = TrimWhiteSpace(x) ;r = "SysCAD 9.2" $
