Class StringFunctions
public class StringFunctions
extends java.lang.Object
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 Constructor Description StringFunctions() -
Method Summary
Modifier and Type Method Description static java.lang.StringcharAt(java.lang.String s1, int i)Returns a one character string that contains the character that is at the positioniin the strings1.static java.lang.Stringchomp(java.lang.String s)Chop off the new line character(s) from the end of the string.static intcodePointAt(java.lang.String s1, int i)static intcodePointBefore(java.lang.String s1, int i)static intcodePointCount(java.lang.String s1, int i, int j)static intcompareTo(java.lang.String s1, java.lang.String s2)static intcompareToIgnoreCase(java.lang.String s1, java.lang.String s2)static booleancontains(java.lang.String s1, java.lang.String s2)static booleanendsWith(java.lang.String s1, java.lang.String s2)static java.lang.Longindex(java.lang.String s1, java.lang.String s2)Implements the functionality of the methods1.indexOf(s2)static java.lang.LongindexAfter(java.lang.String s1, java.lang.String s2, int i)Implements the functionality of the methods1.indexOf(s2,i)static booleanisEmpty(java.lang.String s1)static java.lang.LonglastIndex(java.lang.String s1, java.lang.String s2)Implements the functionality of the methods1.lastIndexOf(s2)static java.lang.LonglastIndexAfter(java.lang.String s1, java.lang.String s2, int i)Implements the functionality of the methods1.lastIndexOf(s2,i)static java.lang.Stringlcase(java.lang.String s)Return a string lower cased.static java.lang.Stringleft(java.lang.String s, int len)Returnlennumber of characters from the left (the beginning) of the string.static java.lang.Stringltrim(java.lang.String s)Trim the white spaces from the start of the string.static java.lang.Stringmid(java.lang.String s, int start, int len)Return a substring from the string that starts at the positionstartand has a length oflen.static java.lang.StringreplaceAll(java.lang.String s1, java.lang.String regex, java.lang.String s2)static java.lang.StringreplaceFirst(java.lang.String s1, java.lang.String regex, java.lang.String s2)static java.lang.Stringright(java.lang.String s, int len)Returnlennumber of characters from the right (the end) of the string.static java.lang.Stringrtrim(java.lang.String s)Trim the white spaces from the end of the string.static java.lang.Stringspace(int len)Return a string that islennumber of space characters.static booleanstartsWith(java.lang.String s1, java.lang.String s2)static java.lang.Stringstring(int len, java.lang.String s)Return a string that islentimes the character ins.static intstrlen(java.lang.String s1)static java.lang.Stringstrreverse(java.lang.String s)Return a string with the characters reversed.static java.lang.Stringtrim(java.lang.String s)static java.lang.Stringucase(java.lang.String s)Return a string upper cased.
-
Constructor Details
-
StringFunctions
public StringFunctions()
-
-
Method Details
-
chomp
public static java.lang.String chomp(java.lang.String s)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
-
ltrim
public static java.lang.String ltrim(java.lang.String s)Trim the white spaces from the start of the string.- Parameters:
s- the string to trim.- Returns:
- the trimmed string
-
rtrim
public static java.lang.String rtrim(java.lang.String s)Trim the white spaces from the end of the string.- Parameters:
s- the string to trim- Returns:
- the trimmed string
-
left
public static java.lang.String left(java.lang.String s, int len)Returnlennumber of characters from the left (the beginning) of the string.- Parameters:
s- parameterlen- parameter- Returns:
- return value
-
mid
public static java.lang.String mid(java.lang.String s, int start, int len) throws BasicRuntimeExceptionReturn a substring from the string that starts at the positionstartand has a length oflen.- Parameters:
s- parameterstart- parameterlen- parameter- Returns:
- return value
- Throws:
BasicRuntimeException- incorrect parameter
-
right
public static java.lang.String right(java.lang.String s, int len)Returnlennumber of characters from the right (the end) of the string.- Parameters:
s- parameterlen- parameter- Returns:
- return value
-
space
public static java.lang.String space(int len)Return a string that islennumber of space characters.- Parameters:
len- parameter- Returns:
- return value
-
string
public static java.lang.String string(int len, java.lang.String s)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
public static java.lang.String strreverse(java.lang.String s)Return a string with the characters reversed.- Parameters:
s- parameter- Returns:
- return value
-
ucase
public static java.lang.String ucase(java.lang.String s)Return a string upper cased.- Parameters:
s- parameter- Returns:
- return value
-
lcase
public static java.lang.String lcase(java.lang.String s)Return a string lower cased.- Parameters:
s- parameter- Returns:
- return value
-
trim
public static java.lang.String trim(java.lang.String s) -
index
public static java.lang.Long index(java.lang.String s1, java.lang.String s2)Implements the functionality of the methods1.indexOf(s2)- Parameters:
s1- parameters2- parameter- Returns:
- return value
-
lastIndex
public static java.lang.Long lastIndex(java.lang.String s1, java.lang.String s2)Implements the functionality of the methods1.lastIndexOf(s2)- Parameters:
s1- parameters2- parameter- Returns:
- return value
-
indexAfter
public static java.lang.Long indexAfter(java.lang.String s1, java.lang.String s2, int i)Implements the functionality of the methods1.indexOf(s2,i)- Parameters:
s1- parameters2- parameteri- parameter- Returns:
- return value
-
lastIndexAfter
public static java.lang.Long lastIndexAfter(java.lang.String s1, java.lang.String s2, int i)Implements the functionality of the methods1.lastIndexOf(s2,i)- Parameters:
s1- parameters2- parameteri- parameter- Returns:
- return value
-
charAt
public static java.lang.String charAt(java.lang.String s1, int i)Returns a one character string that contains the character that is at the positioniin the strings1.- Parameters:
s1- parameteri- parameter- Returns:
- return value
-
replaceAll
public static java.lang.String replaceAll(java.lang.String s1, java.lang.String regex, java.lang.String s2) -
replaceFirst
public static java.lang.String replaceFirst(java.lang.String s1, java.lang.String regex, java.lang.String s2) -
strlen
public static int strlen(java.lang.String s1)- Parameters:
s1- parameter- Returns:
- the length of the string
-
codePointAt
public static int codePointAt(java.lang.String s1, int i) -
codePointBefore
public static int codePointBefore(java.lang.String s1, int i) -
codePointCount
public static int codePointCount(java.lang.String s1, int i, int j) -
compareTo
public static int compareTo(java.lang.String s1, java.lang.String s2) -
compareToIgnoreCase
public static int compareToIgnoreCase(java.lang.String s1, java.lang.String s2) -
contains
public static boolean contains(java.lang.String s1, java.lang.String s2) -
endsWith
public static boolean endsWith(java.lang.String s1, java.lang.String s2) -
startsWith
public static boolean startsWith(java.lang.String s1, java.lang.String s2) -
isEmpty
public static boolean isEmpty(java.lang.String s1)
-