Class StringFunctions

java.lang.Object
com.scriptbasic.utility.functions.StringFunctions

public class StringFunctions extends 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 Details

    • StringFunctions

      public StringFunctions()
  • Method Details

    • chomp

      public static String chomp(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
    • cstr

      public static String cstr(Object o) throws BasicRuntimeException
      Returns string for the argument.
      Parameters:
      o - argument to be converted
      Returns:
      string value
      Throws:
      BasicRuntimeException - failed to convert to string
    • ltrim

      public static String ltrim(Object o) throws BasicRuntimeException
      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

      public static String rtrim(Object o) throws BasicRuntimeException
      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

      public static String left(Object o, int len) throws BasicRuntimeException
      Return len number of characters from the left (the beginning) of the string.
      Parameters:
      o - parameter
      len - parameter
      Returns:
      return value
      Throws:
      BasicRuntimeException - if cannot convert to string
    • mid

      public static String mid(Object o, int start, int len) throws BasicRuntimeException
      Return a substring from the string that starts at the position start and has a length of len.
      Parameters:
      o - parameter
      start - parameter
      len - parameter
      Returns:
      return value
      Throws:
      BasicRuntimeException - incorrect parameter
    • right

      public static String right(Object o, int len) throws BasicRuntimeException
      Return len number of characters from the right (the end) of the string.
      Parameters:
      o - parameter
      len - parameter
      Returns:
      return value
      Throws:
      BasicRuntimeException - if cannot convert to string
    • space

      public static String space(int len)
      Return a string that is len number of space characters.
      Parameters:
      len - parameter
      Returns:
      return value
    • string

      public static String string(int len, 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 String strreverse(String s)
      Return a string with the characters reversed.
      Parameters:
      s - parameter
      Returns:
      return value
    • ucase

      public static String ucase(String s)
      Return a string upper cased.
      Parameters:
      s - parameter
      Returns:
      return value
    • lcase

      public static String lcase(String s)
      Return a string lower cased.
      Parameters:
      s - parameter
      Returns:
      return value
    • trim

      public static String trim(Object o) throws BasicRuntimeException
      Throws:
      BasicRuntimeException
    • index

      public static Long index(String s1, String s2)
      Implements the functionality of the method s1.indexOf(s2)
      Parameters:
      s1 - parameter
      s2 - parameter
      Returns:
      return value
    • lastIndex

      public static Long lastIndex(String s1, String s2)
      Implements the functionality of the method s1.lastIndexOf(s2)
      Parameters:
      s1 - parameter
      s2 - parameter
      Returns:
      return value
    • indexAfter

      public static Long indexAfter(String s1, 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 Long lastIndexAfter(String s1, 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 String charAt(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 String replaceAll(String s1, String regex, String s2)
    • replaceFirst

      public static String replaceFirst(String s1, String regex, String s2)
    • strlen

      public static int strlen(String s1)
      Parameters:
      s1 - parameter
      Returns:
      the length of the string
    • codePointAt

      public static int codePointAt(String s1, int i)
    • codePointBefore

      public static int codePointBefore(String s1, int i)
    • codePointCount

      public static int codePointCount(String s1, int i, int j)
    • compareTo

      public static int compareTo(String s1, String s2)
    • compareToIgnoreCase

      public static int compareToIgnoreCase(String s1, String s2)
    • contains

      public static boolean contains(String s1, String s2)
    • endsWith

      public static boolean endsWith(String s1, String s2)
    • startsWith

      public static boolean startsWith(String s1, String s2)
    • isEmpty

      public static boolean isEmpty(String s1)