beautypg.com

Section 11. string functions, 1 expressions with strings, 1 constant strings – Campbell Scientific CR9000X Measurement and Control System User Manual

Page 397: 2 add strings, 3 subtraction of strings, 4 string conversion to/from numeric

background image

Section 11. String Functions

11.1 Expressions with Strings

11.1.1 Constant Strings

Fixed (constant) strings can be used in expressions using quotation marks “”.
For example, FirstName = “Mike” causes the string variable FirstName to be
assigned “Mike”.

11.1.2 Add Strings

Strings can be concatenated using the ‘+’ operator or the ‘&’ operator.

If you need to concatenate strings and variables, use the ‘+’ operator.

When using the ‘&’ operator, the values being concatenated must be strings
(integers will be converted to strings). When working strictly with strings the
‘&’ operator can be safer to use than the ‘+’ operator, because with the ‘&’
operator there is no danger of a value being converted from a string to an
integer.

Example

FullName = FirstName + “ “ + MiddleName + “ “ + LastName

FullName = FirstName & “ “ & MiddleName & “ “ & LastName

(The “ “ puts a space between the names.)

11.1.3 Subtraction of Strings

String1-String2 results in an integer in the range of –255..+255. Starting with
the first character in each string, the characters in string2 is subtracted from the
character in string1 until the difference is non-zero or until the end of each
string is reached. This is mainly used to determine if the strings are the same
or not.

11.1.4 String Conversion to/from Numeric

Conversion of Strings to Numeric and Numeric to Strings is done
automatically when an assignment is made from a string to a numeric or a
numeric to a string, if possible.

For example:

Public Value

‘ default, a IEEE4 float

Public SensorString AS String * 8

‘an ASCII reading from a sensor

Value = SensorString * 1.8 + 32

‘Sensor string is converted to the IEEE4

Value and scaled from Celsius to Fahrenheit.

11-1