Vybe Documentation

Vybe Main page

 

String & Math Functions

Vybe supports a comprehensive set of string manipulation and mathematical functions, largely compatible with VB6/VB.NET.

String Manipulation

Function Syntax Description
Len Len(string) Returns the number of characters in a string.
Left Left(string, length) Returns a string containing a specified number of characters from the left side.
Right Right(string, length) Returns a string containing a specified number of characters from the right side.
Mid Mid(string, start, [length]) Returns a string containing a specified number of characters from a string (1-indexed).
UCase UCase(string) Returns a string converted to uppercase.
LCase LCase(string) Returns a string converted to lowercase.
Trim Trim(string) Returns a string without leading or trailing spaces.
LTrim LTrim(string) Returns a string without leading spaces.
RTrim RTrim(string) Returns a string without trailing spaces.
InStr InStr([start], s1, s2) Returns the position of the first occurrence of one string within another (1-indexed).
InStrRev InStrRev(s1, s2, [start]) Returns the position of the last occurrence of one string within another.
Replace Replace(str, find, replace) Returns a string in which a specified substring has been replaced.
Chr / ChrW Chr(charcode) Returns the character associated with the specified character code.
Asc / AscW Asc(string) Returns an integer representing the character code of the first letter.
Split Split(str, [delim]) Returns a zero-based, one-dimensional array containing a specified number of substrings.
Join Join(array, [delim]) Returns a string created by joining substrings in an array.
StrReverse StrReverse(string) Returns a string in which the character order is reversed.
Space Space(number) Returns a string consisting of the specified number of spaces.
String String(number, char) Returns a repeating character string of the specified length.
StrComp StrComp(s1, s2, [mode]) Compares two strings (-1, 0, 1).
Format Format(expr, [fmt]) Returns a string formatted according to instructions in a format String expression.
StrConv StrConv(str, conv) Returns a string converted as specified (e.g., Proper Case).

Mathematical Functions

Function Syntax Description
Abs Abs(number) Returns the absolute value of a number.
Int Int(number) Returns the integer portion of a number (floor).
Fix Fix(number) Returns the integer portion of a number (truncate).
Sgn Sgn(number) Returns -1, 0, or 1 indicating the sign of a number.
Sqr Sqr(number) Returns the square root of a number.
Rnd Rnd() Returns a random single-precision number between 0 and 1.
Round Round(num, [places]) Rounds a number to a specified number of decimal places.
Log Log(number) Returns the natural logarithm of a number.
Exp Exp(number) Returns e raised to the power of a number.
Sin / Cos / Tan Sin(number) Standard trigonometric functions (radians).
Atn / Atan2 Atn(number) Inverse trigonometric functions.
Max / Min Max(a, b) Returns the larger or smaller of two values.
Ceiling / Floor Ceiling(number) Rounds up or down to the nearest integer.
Pow Pow(base, exp) Returns base raised to the power of exponent.

.NET Math Class

The Math class provides additional constants and static methods for advanced calculations.

Member Syntax / Type Description
PI Constant (3.1415...) The ratio of the circumference of a circle to its diameter.
E Constant (2.7182...) The natural logarithmic base.
Log10 Math.Log10(number) Returns the base 10 logarithm of a specified number.
Log Math.Log(num, [base]) Returns the logarithm of a number in a specified base.
Acos / Asin Math.Acos(number) Returns the angle whose cosine/sine is the specified number.
Sinh / Cosh Math.Sinh(number) Returns the hyperbolic sine/cosine of the specified angle.
Tanh Math.Tanh(number) Returns the hyperbolic tangent of the specified angle.
Clamp Math.Clamp(v, min, max) Returns a value clamped to the inclusive range of min and max.

Random Numbers

In addition to the legacy Rnd() function, Vybe supports the .NET Random class for better control.

legacy Rnd

System.Random Class

Dim rng As New Random() ' Optionally provide a seed: New Random(42)
Dim r As Integer = rng.Next()        ' Positive integer
Dim r2 As Integer = rng.Next(100)    ' 0 to 99
Dim r3 As Integer = rng.Next(10, 20) ' 10 to 19
Dim rd As Double = rng.NextDouble()  ' 0.0 to 1.0

Examples

String Manipulation

Dim fullName As String = "John Doe"
Dim initials As String
initials = Left(fullName, 1) & Mid(fullName, Instr(fullName, " ") + 1, 1) 
' result: "JD"

Dim cleanText As String = Trim("  Hello Vybe  ")
Dim loudText As String = UCase(cleanText) ' "HELLO Vybe"

Dim parts() As String
parts = Split("A,B,C", ",")

Math Operations

Dim hypotenuse As Double
hypotenuse = Sqr(Pow(3, 2) + Pow(4, 2)) ' result: 5.0

Dim diceRoll As Integer
Randomize()
diceRoll = Int(Rnd() * 6) + 1 ' result: 1 to 6