My.Strings category contains all built-in functions available in Overbasic for handling strings.
Cstr #
Converts a number (or the result of a numeric-expression) to a string.
Result type: string
Arguments:
- NUMBER: any numeric expression.
Dim s As String = My.Strings.Cstr(2 * 3) 'Result: "6"
FormatNumber #
Returns a number/numeric-expression formatted as specified.
Result type: string
Arguments:
- EXPRESSION: any numeric expression.
- FORMAT: format string
Note:
In the format string:
- “,” (comma) is the thousand separator
- “.” (point) is the decimal separator
- “#” character omits the most significant digit (if zero)
- “%” character formats the number as a percentage
WARNING: thousand and decimal separators in the resulting string will be the separators defined in OS settings.
Dim a As String = My.Strings.FormatNumber(10.2, "0.00") 'Result: "10.20"
Dim b As String = My.Strings.FormatNumber(10.27, "0.0") 'Result: "10.3"
Dim c As String = My.Strings.FormatNumber(0.23, "#.00") 'Result: ".23"
Dim d As String = My.Strings.FormatNumber(10.23, "000000") 'Result: "000010"
Dim e As String = My.Strings.FormatNumber(10.23, "0") 'Result: "10"
Dim f As String = My.Strings.FormatNumber(0.273, "0.0%") 'Result: "27.3%"
Dim g As String = My.Strings.FormatNumber(12345.92827635, "#,##0.00") 'Result: "12,345.93"
Dim h As String = My.Strings.FormatNumber(45.92827635, "#,##0.00") 'Result: "45.93"
Instr #
Returns the position of the first character of STRING2 within STRING1. If STRING2 is not present in STRING1, it returns zero.
Result type: numeric
Arguments:
- START: character (position) where to start searching for STRING2 in STRING1
- STRING1: any string
- STRING2: any string
Dim a As Numeric = My.Strings.Instr(1, "Hello World", "World") 'Result: 7
Dim b As Numeric = My.Strings.Instr(1, "Hello World", "Bye") 'Result: 0
Len #
Returns the length (in characters) of a string.
Result type: numeric
Arguments:
- STRING: any string
Dim l As Numeric = My.Strings.Len("Hello World") 'Result: 11
Ltrim #
Removes any spaces from the left side of a string.
Result type: string
Arguments:
- STRING: any string
Dim s As String = My.Strings.Ltrim(" Hello ") 'Result: "Hello "
Mid #
Returns a substring of STRING.
Result type: string
Arguments:
- STRING: any string
- START: position of first substring character within STRING
- LENGTH: (optional) substring length. If omitted, equals the length of STRING minus START.
Dim s As String = My.Strings.Mid("Hello", 2, 3) 'Result: "ell"
Dim s As String = My.Strings.Mid("Hello", 2) 'Result: "ello"
Rtrim #
Removes any spaces from the right side of a string.
Result type: string
Arguments:
- STRING: any string
Dim s As String = My.Strings.Rtrim(" Hello ") 'Result: " Hello"
Trim #
Removes any left and right spaces in a string.
Result type: string
Arguments:
- STRING: any string
Dim s As String = My.Strings.Trim(" Hello ") 'Result: "Hello"