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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String charAt​(java.lang.String s1, int i)
      Returns a one character string that contains the character that is at the position i in the string s1.
      static java.lang.String chomp​(java.lang.String s)
      Chop off the new line character(s) from the end of the string.
      static int codePointAt​(java.lang.String s1, int i)  
      static int codePointBefore​(java.lang.String s1, int i)  
      static int codePointCount​(java.lang.String s1, int i, int j)  
      static int compareTo​(java.lang.String s1, java.lang.String s2)  
      static int compareToIgnoreCase​(java.lang.String s1, java.lang.String s2)  
      static boolean contains​(java.lang.String s1, java.lang.String s2)  
      static boolean endsWith​(java.lang.String s1, java.lang.String s2)  
      static java.lang.Long index​(java.lang.String s1, java.lang.String s2)
      Implements the functionality of the method s1.indexOf(s2)
      static java.lang.Long indexAfter​(java.lang.String s1, java.lang.String s2, int i)
      Implements the functionality of the method s1.indexOf(s2,i)
      static boolean isEmpty​(java.lang.String s1)  
      static java.lang.Long lastIndex​(java.lang.String s1, java.lang.String s2)
      Implements the functionality of the method s1.lastIndexOf(s2)
      static java.lang.Long lastIndexAfter​(java.lang.String s1, java.lang.String s2, int i)
      Implements the functionality of the method s1.lastIndexOf(s2,i)
      static java.lang.String lcase​(java.lang.String s)
      Return a string lower cased.
      static java.lang.String ltrim​(java.lang.String s)
      Trim the white spaces from the start of the string.
      static java.lang.String mid​(java.lang.String s, int start, int len)
      Return a substring from the string that starts at the position start and has a length of len.
      static java.lang.String replaceAll​(java.lang.String s1, java.lang.String regex, java.lang.String s2)  
      static java.lang.String replaceFirst​(java.lang.String s1, java.lang.String regex, java.lang.String s2)  
      static java.lang.String right​(java.lang.String s, int len)
      Return len number of characters from the right (the end) of the string.
      static java.lang.String rtrim​(java.lang.String s)
      Trim the white spaces from the end of the string.
      static java.lang.String space​(int len)
      Return a string that is len number of space characters.
      static boolean startsWith​(java.lang.String s1, java.lang.String s2)  
      static java.lang.String string​(int len, java.lang.String s)
      Return a string that is len times the character in s.
      static int strlen​(java.lang.String s1)  
      static java.lang.String strreverse​(java.lang.String s)
      Return a string with the characters reversed.
      static java.lang.String trim​(java.lang.String s)  
      static java.lang.String ucase​(java.lang.String s)
      Return a string upper cased.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringFunctions

        public StringFunctions()
    • Method Detail

      • 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
      • mid

        public static java.lang.String mid​(java.lang.String s,
                                           int start,
                                           int len)
        Return a substring from the string that starts at the position start and has a length of len.
        Parameters:
        s - parameter
        start - parameter
        len - parameter
        Returns:
        return value
      • right

        public static java.lang.String right​(java.lang.String s,
                                             int len)
        Return len number of characters from the right (the end) of the string.
        Parameters:
        s - parameter
        len - parameter
        Returns:
        return value
      • space

        public static java.lang.String space​(int len)
        Return a string that is len number 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 is len times the character in s. If the string s contains more than one characters then only the first character is repeated.
        Parameters:
        len - parameter
        s - 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 method s1.indexOf(s2)
        Parameters:
        s1 - parameter
        s2 - parameter
        Returns:
        return value
      • lastIndex

        public static java.lang.Long lastIndex​(java.lang.String s1,
                                               java.lang.String s2)
        Implements the functionality of the method s1.lastIndexOf(s2)
        Parameters:
        s1 - parameter
        s2 - 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 method s1.indexOf(s2,i)
        Parameters:
        s1 - parameter
        s2 - parameter
        i - 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 method s1.lastIndexOf(s2,i)
        Parameters:
        s1 - parameter
        s2 - parameter
        i - 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 position i in the string s1.
        Parameters:
        s1 - parameter
        i - 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)