Difference between revisions of "VeryBASIC"

From TheAlmightyGuru
Jump to: navigation, search
(Variable Types)
(String Manipulation)
Line 49: Line 49:
  
 
==String Manipulation==
 
==String Manipulation==
* Left - Returns the specified number of leftmost characters.
+
===Left===
* Right - Returns the specified number of rightmost characters.
+
result = LEFT(source, length, [reverse])
* SubStr - Returns the specified number of characters from a starting position to an optional ending position.
+
 
* StrTran - Replaces all instances of the specified text with the alternate text.
+
Returns a string containing the leftmost number of characters of the specified string.
 +
 
 +
* result - string
 +
* source - string - The string to read.
 +
* length - long - The number of characters you wish to read.
 +
* reverse - boolean - Optional. If true, searches from right to left.
 +
 
 +
'''Examples'''
 +
Left("This is a test.", 7)
 +
"This is"
 +
 
 +
Left("This is a test.", 7, true)
 +
"a test."
 +
 
 +
===SubString===
 +
result = SUBSTRING(source, start, [length], [reverse])
 +
 
 +
Returns a portion of the specified string staring from a position and going to a length.
 +
 
 +
* result - string
 +
* source - string - The string to be read.
 +
* start - long - The left-most character position of the string to start (1-based).
 +
* length - long - Optional. The number of characters to return. If not specified, the remaining length of the we returned.
 +
* reverse - boolean - Optional. If true, searches from right to left.
 +
 
 +
'''Examples'''
 +
SubString("This is a test.", 6, 4)
 +
"is a"
 +
 
 +
SubString("This is a test.", 6)
 +
"is a test."
 +
 
 +
SubString("This is a test.", 2, 4, true)
 +
"test"
 +
 
 +
SubString("This is a test.", 8, , true)
 +
"This is"
 +
 
 +
'''Examples'''
 +
result = REPLACE(source, search, replace)
 +
 
 +
Replaces all instances of the replace string in the search string.
 +
 
 +
* result - string
 +
* source - string - The string to be read.
 +
* search - string - The string to search for to be replaced.
 +
* replace - string - The string with which the search string will be replaced.
 +
 
 +
'''Examples'''
 +
Replace("This is a test.", "test", "drill")
 +
"This is a drill."
 +
 
 +
===More===
 
* Split - Returns an array of the string split on the specified strings.
 
* Split - Returns an array of the string split on the specified strings.
 
* Replicate - Returns a string of the replicated character the specified number of times.
 
* Replicate - Returns a string of the replicated character the specified number of times.
 
* Upper - Returns the string with all lower case letters converted to upper case.
 
* Upper - Returns the string with all lower case letters converted to upper case.
 
* Lower - Returns the string with all upper case letters converted to lower case.
 
* Lower - Returns the string with all upper case letters converted to lower case.
* Trim - Removes white space or specified characters from either side of the string.
+
* TrimAll - Removes white space or specified characters from both sides of the string.
* TrimLeft - Removes white space or specified characters from the left side of the string.
+
* Trim - Removes white space or specified characters from the left side of the string (reversible).
* TrimRright - Removes white space or specified characters from the right side of the string.
+
* Pad - Adds a specified number of white space or specified characters to the left of the string and returns the result (reversible).
* PadLeft - Adds a specified number of white space or specified characters to the left of the string and returns the result.
+
* Stuff - Injects the specified string into another at a starting point and returns the result.
* PadRight - Adds a specified number of white space or specified characters to the right of the string and returns the result.
+
* Extract - Returns the extracted string between the specified start and end strings (reversible).
* Stuff - Injects the specified string into another at a starting point, replacing the specified number of characters, and returns the result.
+
* Join - Returns a formatted string from an array of strings with the specified delimiter between each element (reverse of split).
* Extract - Returns the extracted string between the specified start and end strings.
+
* Reverse - Returns the reverse of the specified string.
 +
* Length (len) - Returns the length of the string.
 +
* Find - Returns the leftmost position of the sub string within the specified string (reversible).
 +
* Occurs - Returns the number of times the search string occurs in the specified string.
 +
* Format - Returns the specified string formatted by the format string.
  
 
==Flow==
 
==Flow==

Revision as of 17:16, 22 November 2021

VeryBASIC is a version of the BASIC computer language I've been designing with the hope of eventually programming it. The goal is to expand on the original BASIC formula by adding a lot of additional commands and features that aren't part of the original specifications, but are often desired by programmers. For example, there are great modern BASIC adaptions like FreeBASIC, however, they were meant primarily to allow simple porting of QuickBASIC to 32 and 64-bit operating systems, and only extend the language a little relying on libraries from other languages to advance it further. VeryBASIC is meant to expand on the language to give it a lot of new commands and features, putting it in-line with modern languages.

Variables

Variables can optionally be defined with a value. Constants must be defined with a value, but that value may be a variable. Variables can be manually cleared.

  • Var [static] [global] type name [= value] - Used to define a variable.
  • Const [global] type name = value - Used to define a variable whose value, once set, can never change.
  • Clear - Clears the specified variable from memory.

Allocation

By default, variables are allocated automatically, but they can be allocated as static. Constants are always static.

Scope

By default, variables are scoped locally, but can be scoped globally.

Pointers

All variables can be accessed by their memory pointer.

Numericals

Integers

All integers are signed by default, but can be declared as unsigned. All 16-bit or higher integers use the endianess of their native platform, but can be defined differently.

  • Byte - 8-bit integer.
  • Short - 16-bit integer.
  • Integer - 32-bit integer.
  • Long - 64-bit integer.
  • Great - 128-bit integer (if hardware allows).

Floats

  • Single - 32-bit float.
  • Double - 64-bit float.
  • Quad - 128-bit float (if hardware allows).

General

A general number is built more like a string than a binary number. Because of this, you can't perform CPU-level math on it, making calculations particularly slow, but, it can be any size a string can support.

Strings

  • String - 8-bit characters.
  • WString - 16-bit characters.
  • UniString - UTF-8 Unicode characters.

Time

  • Date - A date value stored as signed 32-bit integer.
  • Time - A date and time value stored as a signed 64-bit integer.
  • TimeStamp - A time value with time zone.

Logical

  • Boolean - A true or false value stored as an 8-bit integer.

String Manipulation

Left

result = LEFT(source, length, [reverse])

Returns a string containing the leftmost number of characters of the specified string.

  • result - string
  • source - string - The string to read.
  • length - long - The number of characters you wish to read.
  • reverse - boolean - Optional. If true, searches from right to left.

Examples

Left("This is a test.", 7)

"This is"

Left("This is a test.", 7, true)

"a test."

SubString

result = SUBSTRING(source, start, [length], [reverse])

Returns a portion of the specified string staring from a position and going to a length.

  • result - string
  • source - string - The string to be read.
  • start - long - The left-most character position of the string to start (1-based).
  • length - long - Optional. The number of characters to return. If not specified, the remaining length of the we returned.
  • reverse - boolean - Optional. If true, searches from right to left.

Examples

SubString("This is a test.", 6, 4)

"is a"

SubString("This is a test.", 6)

"is a test."

SubString("This is a test.", 2, 4, true)

"test"

SubString("This is a test.", 8, , true)

"This is"

Examples

result = REPLACE(source, search, replace)

Replaces all instances of the replace string in the search string.

  • result - string
  • source - string - The string to be read.
  • search - string - The string to search for to be replaced.
  • replace - string - The string with which the search string will be replaced.

Examples

Replace("This is a test.", "test", "drill")

"This is a drill."

More

  • Split - Returns an array of the string split on the specified strings.
  • Replicate - Returns a string of the replicated character the specified number of times.
  • Upper - Returns the string with all lower case letters converted to upper case.
  • Lower - Returns the string with all upper case letters converted to lower case.
  • TrimAll - Removes white space or specified characters from both sides of the string.
  • Trim - Removes white space or specified characters from the left side of the string (reversible).
  • Pad - Adds a specified number of white space or specified characters to the left of the string and returns the result (reversible).
  • Stuff - Injects the specified string into another at a starting point and returns the result.
  • Extract - Returns the extracted string between the specified start and end strings (reversible).
  • Join - Returns a formatted string from an array of strings with the specified delimiter between each element (reverse of split).
  • Reverse - Returns the reverse of the specified string.
  • Length (len) - Returns the length of the string.
  • Find - Returns the leftmost position of the sub string within the specified string (reversible).
  • Occurs - Returns the number of times the search string occurs in the specified string.
  • Format - Returns the specified string formatted by the format string.

Flow

  • For...Next
  • Do...Loop
  • While...Wend

Conditionals

  • If

Boolean Operators

  • And, Or, Xor, Nor, Nand

Bit Manipulation

  • BitSet, BitGet, BitShiftLeft, BitShiftRight