DAQFactory supports many functions for string manipulation.
Asc(Character):
Converts the given character into its ASCII value. If you pass a string, only the first character is converted. For example:
Asc({“ABC”,"DEF"}) returns {65,68}
AscA(String):
Same as Asc, but works on a single string and returns the ASCII value for each character in that string in an array. Only works with the first string. For example:
AscA({“ABC”,”DEF”}) returns {65,66,67}
Chr(Value):
Converts the given value into the ASCII representation of that value. For example:
Chr({65,66,67}) returns {“A”,"B","C"}
ChrA(Array of Values):
Same as Chr, but takes an array of values and creates a single string out of them. For example:
ChrA({65,66,67}) returns “ABC”
Compare(String1,String2):
Compares two strings, case sensitive. Returns 0 if they match, -1 if String1 is less than String2, +1 if String1 is greater than String2. In most cases, it is easier to use the ==, < and > operators. Examples of Compare():
Compare("abcdef","abcdef") returns 0 but
Compare("abcdef","abCDef") returns 1.
CompareNoCase(String1,String2):
Compares two strings case insensitive. Returns 0 if they match, -1 if String1 is less than String2, +1 if String1 is greater than String2. For example:
CompareNoCase("abcdef","abCDef") returns 0 but
CompareNoCase("abcdef","bdfsef") returns -1
Delete(String,Index,# Chars):
Deletes x number of chars starting at index in string. For example:
Delete("abcdef",3,2) returns "abcf"
DoubleToStr(Value):
This converts the given number to a string with up to 15 sig figs (the max for a double precision floating point value). This is essentially the same as Format("%f",Value)
Evaluate(String):
Evaluates the string as if it was an expression. Returns a value. For example:
Evaluate("1+1") returns 2.
Find(String,String to find,Start point):
Finds the given string within the other given string starting at the given start point. Returns the index of the given search string or -1 if not found. For example:
Find("abcdef","cd",0) returns 2.
FindExpr(String, Regular Expression):
Finds the first instance that matches the regular expression. Regular expressions are a somewhat standard method of specifying more complicated search strings. They are a bit more complicated, but rather powerful when used properly. DAQFactory follows pretty closely to the regular expressions used by Microsoft Visual C++ 6.0. The details about using regular expressions can found online. Some beginning information is provided at the end of this section. The result of this function is an array with two values. The first value is the first character that matches the expression. The second character is the length of the matching string. {-1,-1} is returned if nothing is found.
FindExpr("abcdef","[^a]cd") returns {1,3}.
Unlike most regular expression search engines, FindExpr can search for the ASCII character 0. So:
FindExpr("abc" + chr(0) + "def", "[^a]c"+Chr(0)+"d") returns {1,4}
FindOneOf(String,Chars to find):
Finds the first instance of one of the given chars. -1 if not found. Returns an index. For example:
FindOneOf("abcdef","ce") returns 2.
Format(FormatString,Value,[Value2],...):
Performs a standard C printf style format. You can have up to 19 values in a single call. To format a time value, see the FormatDateTime() function in the section on Time. The following types are supported (case sensitive):
c or C: single byte character
d or i: signed decimal integer
o : unsigned octal integer
u : unsigned decimal integer
x : unsigned hexadecimal integer, using lowercase "abcdef"
X : unsigned hexadecimal integer, using uppercase "ABCDEF"
e : signed floating point value using exponential notation with a lower case "e"
E : same as e but with an upper case "E"
f : signed floating point value without exponent.
g : signed floating point value with optional exponent depending on size of resultant string. In other words, 3.0 would be simply 3, but 3 million would be 3e+006
G : same as g but with an upper case "E" for the exponent.
s or S : a string
For the details of using the flags, width and precision arguments in printf, we refer you to any C programming text.
For example:
Format("My Value: %.3f",MyChannel[0]) returns "My Value 34392.492"
You can also use several \ modifiers to generate special characters:
\n : new line character, a line feed, ASCII 10
\r : return character, a carriage return, ASCII 13
\t : tab character, ASCII 9
\yyy: the ASCII character with the given code. All three digits are required. So, \065 will generate an A.
\xzz: same as above, but the code is given in hex. The x is required along with two hexadecimal digits. So, \x0a is the same as \n or ASCII 10.
\\ : a backslash
GetLength(String):
Returns the length of the string. For example:
GetLength("abcdef") returns 6
HideHidden(String)
Takes all non-printing characters (ASCII values less than 32 or greater than 126) and removes them from the string. For example:
HideHidden(“abc” + Chr(9) + “def” + Chr(13)) returns “abcdef”
Insert(String,Index,Insert String):
Inserts the given string into the other given string starting at index. For example:
Insert("abcdef",3,"abc") returns "abcabcdef"
Left(String,# Chars):
Returns x number of characters starting from the left of the string. For example:
Left("abcdef",4) returns "abcd"
LTrim(String), RTrim(String):
Trims leading or trailing spaces. For example:
LTrim(" abcdef") returns "abcdef"
MakeLower(String):
Returns the string converted to all lowercase. For example:
MakeLower("Abcdef") returns "abcdef"
MakeReverse(String):
Flips the string. For example:
Reverse("abcdef") returns "fedcba"
MakeUpper(String):
Returns the string converted to all uppercase. For example:
MakeUpper("abcdef") returns "ABCDEF"
Mid(String,Start,# Chars):
Returns a subset from the center of the string. Start is zero indexed. For example:
Mid("abcdef",2,3) returns "cde"
Parse(String,Index,Parse By):
Assumes String is a list of values separated by Parse By. Returns the given index item into this list. For example:
Parse("this,is,a,test",2,",") returns "a". Note 0 indexing (as always)
If you specify a negative Index, then parse will completely parse the String and return an array of the separated strings. For example:
Parse("this,is,a,test",-1,",") returns {"this","is","a","test"}
If you only need one element out of your delimited string, use the first, indexed method. If, however, you are going to work with all the elements, it is much faster to use the second method and work through the array then to repetitively call Parse() with incrementing indices.
Remove(String,Remove Char):
Removes all instances of char in string. For example:
Remove("abcdef","a") returns "bcdef"
Replace(String,Old,New):
Replaces all instances of old with new within string. For example:
Replace("abcabc","a","b") returns "bbcbbc"
ReverseFind(String,Char to find):
Just like find, but starts from the back. Returns an index (from the front). For example:
ReverseFind("abcdef","cd") returns 2.
Right(String,# Chars):
Same as Left() but from the right. For Example:
Right("abcdef",4) returns "cdef"
ShowHidden(String)
Takes all non-printing characters (ASCII values less than 32 or greater than 126) and displays their ASCII code with a backslash in front. For example:
ShowHidden("abc" + Chr(9) + "def" + Chr(13)) returns "abc\009def\013"
StrToDouble(String):
Converts a string into a double for use in standard math functions. Converts up to the first invalid character. Returns a value. If the first character is invalid, it will return NaN. For example:
StrToDouble("534.27") returns 534.27.
StrToDouble("534sd27") returns 534.
StrToDouble("sd27") returns NaN.
You can also specify hex or binary values by proceeding the number with "0x" or "0b":
StrToDouble("0xff") returns 255.
Although the function is called StrToDouble, if you use the hex or binary notation an integer is returned. Also, as when entering hex and binary constants, only the values between 0 and 2^31 are supported.
To convert date and time strings to DAQFactory times, use the StrToTime() function shown in the section on Time.
Supported operands:
== (same as compare and is case sensitive)
+ (concatenates the strings)
>
<
>=
<=
Regular expressions are made up of regular ASCII characters (including control codes generated with functions like Chr()) and tags. A tag is that part of a regular expression which consists of any of the symbols, or characters, listed in the table below. For example, the regular expression "s+.{2,4}" has two (2) tags: the "s+" which specifies that the "s" will be searched for one or more times; and ".{2,4}", which specifies that there must be two (2) to four (4) characters (except newline characters) following the occurrence of the "s". In essence tags allow you to break up a rule into separate search components.
\ |
Marks the next character as special. Precede any special character that you would actually like to search for with this symbol. For example, to search for '^' you would put '\^'. |
^ |
A match occurs only if the character following this symbol is found at the beginning of a line or input. |
$ |
A match occurs only if the character following this symbol is found at the end of the input, or line. |
* |
Searches for the preceding character zero or more times. For this implementation you must define more than one character. If only one character is specified in the regular expression then no matches will be found. That means that /zo*/ matches z and zoo, but /z*/ will match nothing because only one character has been specified. |
+ |
Searches for the preceding character one or more times. |
? |
Searches for the preceding character either one time or not at all. It cannot be defined if only one character is specified in the regular expression. |
. |
Matches any single character except Chr(10). |
(pattern) |
Matches the specified pattern and remembers each match via unique indexes for each match found. Only characters enclosed within parentheses will be considered patterns. The found substring can then be retrieved by using '\0'-'\9' in the regular expression, where '0'-'9' is the identifying index number of that particular pattern. For example: '(re).*\0s+ion' will match 'regular expression' because it first finds the pattern 're' and remembers the pattern with an index of 0. '.*' will then match 'gular exp' in 'regular expression'. Then we look for the same pattern again by inserting '\0' into the regular expresson, which matches the second occurrence of 're' in 'regular expression'. Finally, 's+ion' matches 'ssion'. |
x|y |
Matches either character 'x' or 'y'. You can combine more than two characters (e.g. 'x|y|z'). |
{n} |
The preceding character must match exactly 'n' times (non-negative values only). |
{n,} |
The preceding character must match at least 'n' times (non-negative values only). |
{n,m} |
The preceding character must match at least 'n' times and at most 'm' times. (n,m - non-negative numbers only). |
[xyz] |
A character set. A match occurs if any one of the enclosed characters is found. |
[^xyz] |
A non-matching character set. A match occurs if any character that is not in the set is found. |
\b |
Matches a word boundary. A boundary occurs between two non-space characters. Also, the ascii format characters, Chr(10) through Chr(13) do not define a word boundary. For example, the expression "me" + chr(10) only has one word boundary which occurs between the "m" and the "e". |
\B |
Searches for a non-word boundary. The exact opposite of the previous symbol ("\b"). A match occurs for any boundary between space characters or between a non-space character and a space character. For example, the expression " me"+chr(10)+" " has three (3) non-word boundaries: between the first space and the "m"; between the "e" and the newline character; and between the newline character and the last space. |
\d |
A match occurs for any digit 0-9. |
\D |
Matches any non-digit character. |
\f |
Matches a form feed (same as chr(12)) |
\n |
Matches a new-line character. (same as chr(10)) |
\r |
Matches a carriage return character. (same as chr(13)) |
\s |
Matches any white space character. |
\S |
Matches any non-white space character. |
\t |
Matches a tab character. (same as chr(9)) |
\v |
Matches any vertical tab character. (same as chr(11)) |
\w |
Matches any alphabetic character including underscores. [A-Z a-z 0-9 _]. |
\W |
Matches any non-alphabetic character. |
\num |
Matches any characters defined as a pattern with a unique index between 0 and 9. A match occurs if the pattern identified by 'num' is found (see the pattern description for an example). |
/n/ |
A match occurs if a character is located with an ascii code of 'n'. 'n' must be between 1 and 255. You'll typically just want to use Chr() in creating your regular expression instead: FindExpr(MyVar, "abc" + chr(0) + "def") |