7.9.19.6 String Use of ASCII / ANSII Codes
Table 50. Use of ASCII / ANSII Codes Examples
Expression Comments Result
LongVar (7) = ASCII("#")
35
LongVar (8) = ASCII("*")
42
LongVar (9) = "#"
Cannot be converted to Long with
NULL
NAN
LongVar (1) = "#"-""
Can be converted to Long without
NULL
35
7.9.19.7 Formatting Strings
Table 51. Formatting Strings Examples
Expression Result
Str(1)=123e4
Str(2)=FormatFloat(123e4,"%12.2f")
Str(3)=FormatFloat(Values(2)," The battery is %.3g Volts ")
Str(4)=Strings(3,1,InStr(1,Strings(3),"The battery is ",4))
Str(5)=Strings(3,1,InStr(1,Strings(3),"is ",2) + 3)
1230000
1230000.00
“The battery is 12.4 Volts”
12.4 Volts
Str(6)=Replace("The battery is 12.4 Volts"," is "," = ")
Str(7)=LTrim("The battery is 12.4 Volts")
Str(8)=RTrim("The battery is 12.4 Volts")
Str(9)=Trim("The battery is 12.4 Volts")
Str(10)=UpperCase("The battery is 12.4 Volts")
The battery = 12.4 Volts
The battery is 12.4 Volts
The battery is 12.4 Volts
The battery is 12.4 Volts
THE BATTERY IS 12.4 VOLTS
Str(12)=Left("The battery is 12.4 Volts",5)
Str(13)=Right("The battery is 12.4 Volts",7)
The b
CRBasic Example 60. Formatting Strings
'This program example demonstrates the formatting of string variables. To run the
'demonstration, send this program to the CR1000. String formatting will occur
'automatically.
'Objective:
'Extract "12.4 Volts" from the string "The battery is 12.4 Volts"
Public StringVar As String
BeginProg
'Note line continuation character _
StringVar() = Mid("The battery is 12.4 Volts", _
InStr(1,"The battery is 12.4 Volts"," is ",2)+3,Len("The battery is 12.4 Volts"))
287