Class StringFunctions
This class implements string functions for the BASIC interpreter. Most of the
methods implement a wrapper for the method of the same name in the class
java.lang.String. These methods in the class java.lang.String
are not static and therefore need a String object to work on. The wrapper
methods are static and take the first argument as the String object to work
on. In other words if in Java you would write
s.xyz(parameterlist)
to call the method xyz() then in BASIC you will be able to call
xyz(s, parameterlist)
The documentation of the methods implemented in String are
not repeated here. Other methods, that implement BASIC like string functions
not implemented in the class java.lang.String are documented in this
class.
- Author:
- Peter Verhas
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns a one character string that contains the character that is at the positioniin the strings1.static StringChop off the new line character(s) from the end of the string.static intcodePointAt(String s1, int i) static intcodePointBefore(String s1, int i) static intcodePointCount(String s1, int i, int j) static intstatic intcompareToIgnoreCase(String s1, String s2) static booleanstatic StringReturns string for the argument.static booleanstatic LongImplements the functionality of the methods1.indexOf(s2)static LongindexAfter(String s1, String s2, int i) Implements the functionality of the methods1.indexOf(s2,i)static booleanstatic LongImplements the functionality of the methods1.lastIndexOf(s2)static LonglastIndexAfter(String s1, String s2, int i) Implements the functionality of the methods1.lastIndexOf(s2,i)static StringReturn a string lower cased.static StringReturnlennumber of characters from the left (the beginning) of the string.static StringTrim the white spaces from the start of the string.static StringReturn a substring from the string that starts at the positionstartand has a length oflen.static StringreplaceAll(String s1, String regex, String s2) static StringreplaceFirst(String s1, String regex, String s2) static StringReturnlennumber of characters from the right (the end) of the string.static StringTrim the white spaces from the end of the string.static Stringspace(int len) Return a string that islennumber of space characters.static booleanstartsWith(String s1, String s2) static StringReturn a string that islentimes the character ins.static intstatic Stringstrreverse(String s) Return a string with the characters reversed.static Stringstatic StringReturn a string upper cased.
-
Constructor Details
-
StringFunctions
public StringFunctions()
-
-
Method Details
-
chomp
Chop off the new line character(s) from the end of the string. If there are more than one new line character at the end of the string then all of them are cut off.If there are no new line characters at the end of the string then the unaltered string is returned.
- Parameters:
s- the string to chomp- Returns:
- the string without the trailing new lines
-
cstr
Returns string for the argument.- Parameters:
o- argument to be converted- Returns:
- string value
- Throws:
BasicRuntimeException- failed to convert to string
-
ltrim
Trim the white spaces from the start of the string.- Parameters:
o- the string to trim.- Returns:
- the trimmed string
- Throws:
BasicRuntimeException- if cannot convert to string
-
rtrim
Trim the white spaces from the end of the string.- Parameters:
o- the string to trim- Returns:
- the trimmed string
- Throws:
BasicRuntimeException- if cannot convert to string
-
left
Returnlennumber of characters from the left (the beginning) of the string.- Parameters:
o- parameterlen- parameter- Returns:
- return value
- Throws:
BasicRuntimeException- if cannot convert to string
-
mid
Return a substring from the string that starts at the positionstartand has a length oflen.- Parameters:
o- parameterstart- parameterlen- parameter- Returns:
- return value
- Throws:
BasicRuntimeException- incorrect parameter
-
right
Returnlennumber of characters from the right (the end) of the string.- Parameters:
o- parameterlen- parameter- Returns:
- return value
- Throws:
BasicRuntimeException- if cannot convert to string
-
space
Return a string that islennumber of space characters.- Parameters:
len- parameter- Returns:
- return value
-
string
Return a string that islentimes the character ins. If the stringscontains more than one characters then only the first character is repeated.- Parameters:
len- parameters- parameter- Returns:
- return value
-
strreverse
Return a string with the characters reversed.- Parameters:
s- parameter- Returns:
- return value
-
ucase
Return a string upper cased.- Parameters:
s- parameter- Returns:
- return value
-
lcase
Return a string lower cased.- Parameters:
s- parameter- Returns:
- return value
-
trim
- Throws:
BasicRuntimeException
-
index
Implements the functionality of the methods1.indexOf(s2)- Parameters:
s1- parameters2- parameter- Returns:
- return value
-
lastIndex
Implements the functionality of the methods1.lastIndexOf(s2)- Parameters:
s1- parameters2- parameter- Returns:
- return value
-
indexAfter
Implements the functionality of the methods1.indexOf(s2,i)- Parameters:
s1- parameters2- parameteri- parameter- Returns:
- return value
-
lastIndexAfter
Implements the functionality of the methods1.lastIndexOf(s2,i)- Parameters:
s1- parameters2- parameteri- parameter- Returns:
- return value
-
charAt
Returns a one character string that contains the character that is at the positioniin the strings1.- Parameters:
s1- parameteri- parameter- Returns:
- return value
-
replaceAll
-
replaceFirst
-
strlen
- Parameters:
s1- parameter- Returns:
- the length of the string
-
codePointAt
-
codePointBefore
-
codePointCount
-
compareTo
-
compareToIgnoreCase
-
contains
-
endsWith
-
startsWith
-
isEmpty
-