Class STRING

java.lang.Object
com.github.gbenroscience.parser.STRING

public class STRING extends Object
Author:
JIBOYE OLUWAGBEMIRO OLAOLUWA. This class has many methods. Method delete provides 2 constructors.The at takes 2 arguments,the string to manipulate and the index to be deleted from the string.It returns the original string without the element at the specified index. Method delete takes 3 arguments.The string,the index from which deletion is to begin and the index where deletion ends.The returned string is the original string without the characters from the starting index to one index behind the ending index.So the character at the ending index is not deleted. So if we write At( u,0,u.length() ),the whole string is deleted. Method isDouble1 takes a single argument;that is the number string which we wish to know if it is of type double or not. It is a bold attempt by the author to devise a means of checking if a number entry qualifies as a double number string. This checking is done at much higher speeds in comparison to method isDouble.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    contains(String str, String substr)
    contains allows you to verify if an input string contains a given substring.
    static int
    countOccurences(char c, String str)
    Counts how many times a given single character string occurs in a given String object.
    static String
    delete(String u, int i)
    method delete takes 2 arguments,the string to be modified and the index of the character to be deleted
    static String
    delete(String u, int i, int j)
    method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end.
    static String
    delete(String u, String str)
    method delete takes 2 arguments,the string to be modified and the substring to be removed from it.
    static String
    deleteCharsAfter(String str, int i, int num)
    method deleteCharsAfter takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end.
    static String
    doubleToString(double num)
     
    static char
     
    static String
    method firstElement takes one argument and that is the string to be modified.
    static int
    method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
    static int
    method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
    static String
    Returns the first number-like substring starting at the first digit found in the input.
    static String
    method getFirstOccurenceOfDigit takes a String object and returns the first occurence of a number character in the String.
    static boolean
     
    static boolean
     
    static boolean
    boolean Method isDigit can be used to check for single digits i.e 0-9.
    static boolean
    isDigitChar(char c)
    ////////////////////////////////////////////////////////////////////////////
    static boolean
    Checks if a string can be parsed as a double.
    static boolean
    Method isDouble1 is specially built for parsing number strings in my parser.Please do not use it for your own purposes.
    static boolean
    isEven(double a)
    Checks if a given number is even
    static boolean
    isEven(float a)
    Checks if a given number is even
    static boolean
    isEven(int a)
    Checks if a given number is even
    static boolean
     
    static boolean
     
    static boolean
    isFullyDouble allows you to verify if an input string is in double number format or not.
    static boolean
     
    static boolean
    method isLowerCaseWord takes one argument and that is the string whose case we wish to know.
    static boolean
    Checks if a string is a valid number component.
    static boolean
    isOnlyDigits allows you to verify if an input string consists of just digits and the exponential symbol.
    static boolean
     
    static boolean
    method isUpperCaseWord takes one argument and that is the string whose case we wish to know.
    static boolean
     
    static char
     
    static String
    method lastElement takes one argument and that is the string to be modified.
    static void
    main(String[] args)
     
    static int
    nextIndexOf(String str, int index, String str2)
    nextIndexOf allows you to get the next occurence of a substring searching from a point in the string forwards
    static int
    prevIndexOf(String str, int index, String str2)
    prevIndexOf allows you to get the previous occurence of a substring searching from a point in the string backwards
    static String
    purifier allows you to remove all white spaces in a given string,which it receives as its argument
    static String
    purifier(String h, int fromIndex)
    Returns a string where characters from index `fromIndex` onward are purified (spaces and newlines removed), while the prefix [0, fromIndex) is preserved exactly.
    static String
    removeAll(String str, String unwanted)
    removeAll allows you to remove all occurrences of an unwanted string from a given string, which it receives as its argument
    static String
    Allows you to remove commas from a string.
    static String
     
    static String
    repeating(String val, int count)
     
    static String
    method replace takes 4 arguments,the string to be modified, the replacing string, the index at which replacement is to begin and the index where replacement ends plus one i.e replacement ends at index j-1.
    static String
    replaceAll(String str, String replaced, String replacing)
    Replace all literal occurrences of `replaced` in `str` with `replacing`.
    static String
    method reverse takes 1 argument and that is the string to be reversed
    split(String stringTosplit, String splittingObject)
    This is an optimized specialized substitute for String.split in the Java API.
    static String[]
    splits(String stringToSplit, String splittingObject)
    This is an highly optimized specialized substitute for String.split in the Java API.
    static String[]
    splits(String stringTosplit, String[] splittingObjects)
    This is an highly optimized specialized substitute for String.split in the Java API.
    static String
    method toLowerCase takes one argument only and that is input string to be converted to lower case
    static String
    method toUpperCase takes one argument only and that is the input string to be converted to upper case

    Methods inherited from class java.lang.Object

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

    • STRING

      public STRING()
  • Method Details

    • contains

      public static boolean contains(String str, String substr)
      contains allows you to verify if an input string contains a given substring.
      Parameters:
      str - : the string to check
      substr - : the substring to check for
      Returns:
      true or false depending on if or not the input consists of digits alone or otherwise.
    • isOnlyDigits

      public static boolean isOnlyDigits(String h)
      isOnlyDigits allows you to verify if an input string consists of just digits and the exponential symbol. So the method will return true for 32000 but not for 3.2E4.It will also return true for 32E3.No decimal points are allowed
      Parameters:
      h - ..The string to be analyzed.
      Returns:
      true or false depending on if or not the input consists of digits alone or otherwise.
    • isLetter

      public static boolean isLetter(String s)
      Parameters:
      s - The single character string to be examined if it is a letter of the alphabet or not.
      Returns:
      true if the parameter is a valid letter of the English alphabet.
    • removeNewLineChar

      public static String removeNewLineChar(String input)
      Parameters:
      input - The string from which we wish to remove all new line characters.
      Returns:
      a string like the input but free of all new line characters.
    • repeating

      public static String repeating(String val, int count)
    • isFullyDouble

      public static boolean isFullyDouble(String num)
      isFullyDouble allows you to verify if an input string is in double number format or not.
      Parameters:
      num - ..The string to be analyzed.
      Returns:
      true or false depending on if or not the input represents a valid double number
    • firstChar

      public static char firstChar(String u)
    • lastChar

      public static char lastChar(String u)
    • firstElement

      public static String firstElement(String u)
      method firstElement takes one argument and that is the string to be modified.
      Parameters:
      u - the string to be modified
      Returns:
      the first element of the string
      Throws:
      StringIndexOutOfBoundsException
    • lastElement

      public static String lastElement(String u)
      method lastElement takes one argument and that is the string to be modified.
      Parameters:
      u - the string to be modified
      Returns:
      the last element of the string
      Throws:
      StringIndexOutOfBoundsException
    • nextIndexOf

      public static int nextIndexOf(String str, int index, String str2)
      nextIndexOf allows you to get the next occurence of a substring searching from a point in the string forwards
      Parameters:
      str - ..The String being analyzed.
      index - ..The starting point of the search.
      str2 - ..The string whose next occurence we desire.
      Returns:
      the next index of the str2 if found or -1 if not found
    • prevIndexOf

      public static int prevIndexOf(String str, int index, String str2)
      prevIndexOf allows you to get the previous occurence of a substring searching from a point in the string backwards
      Parameters:
      str - ..The String being analyzed.
      index - ..The starting point of the search.
      str2 - ..The string whose previous occurence we desire.
      Returns:
      the previous index of the str2 if found or -1 if not found
    • isSign

      public static boolean isSign(String val)
      Parameters:
      val - the entry being analyzed.
      Returns:
      true if the entry is a + sign or a minus sign
    • isDecimalPoint

      public static boolean isDecimalPoint(String val)
      Parameters:
      val - the entry being analyzed.
      Returns:
      true if the entry is a floating point
    • isExponentOf10

      public static boolean isExponentOf10(String val)
      Parameters:
      val - the entry being analyzed.
      Returns:
      true if the entry is the power of 10 symbol i.e E
    • getFirstOccurenceOfDigit

      public static String getFirstOccurenceOfDigit(String value)
      method getFirstOccurenceOfDigit takes a String object and returns the first occurence of a number character in the String.
      Parameters:
      value - the string to analyze
      Returns:
      the first occurence of a number character in the sequence.
      Throws:
      StringIndexOutOfBoundsException
    • getFirstIndexOfDigit

      public static int getFirstIndexOfDigit(String val)
      method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
      Parameters:
      val - the string to analyze
      Returns:
      the index of the first occurence of a number character in the sequence.
      Throws:
      StringIndexOutOfBoundsException
    • getFirstIndexOfDigitOrPoint

      public static int getFirstIndexOfDigitOrPoint(String val) throws StringIndexOutOfBoundsException
      method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
      Parameters:
      val - the string to analyze
      Returns:
      the index of the first occurence of a number character in the sequence.
      Throws:
      StringIndexOutOfBoundsException
    • countOccurences

      public static int countOccurences(char c, String str)
      Counts how many times a given single character string occurs in a given String object.
      Parameters:
      c - A single character String value whose occurences in another string we wish to count.
      str - The String object that we will search through.
      Returns:
      The number of times c occurs in str
    • getFirstNumberSubstring

      public static String getFirstNumberSubstring(String val)
      Returns the first number-like substring starting at the first digit found in the input. Supports optional decimal point and exponent (E or e) with optional sign. Examples it will extract: "123", "0.45", ".78", "3.14E-10". Note: relies on getFirstIndexOfDigit(val) to return the index of the first digit in val, or -1 if none.
      Parameters:
      val - the string to analyze
      Returns:
      the index of the first occurrence of a number character in the sequence.
      Throws:
      StringIndexOutOfBoundsException
    • removeCommas

      public static String removeCommas(String s)
      Allows you to remove commas from a string.
      Parameters:
      h -
      Returns:
      a string in which the contents of the original have been freed from all commas.
    • purifier

      public static String purifier(String h)
      purifier allows you to remove all white spaces in a given string,which it receives as its argument
      Parameters:
      h - The string to free from white space.
      Returns:
      a string devoid of all white space.
    • purifier

      public static String purifier(String h, int fromIndex)
      Returns a string where characters from index `fromIndex` onward are purified (spaces and newlines removed), while the prefix [0, fromIndex) is preserved exactly. Semantics match the original: only ' ' and '\n' are removed.
      Parameters:
      h - The string to remove white space from.
      fromIndex -
      Returns:
      a string from which white space has been removed starting from index fromIndex.
    • removeAll

      public static String removeAll(String str, String unwanted) throws IndexOutOfBoundsException
      removeAll allows you to remove all occurrences of an unwanted string from a given string, which it receives as its argument
      Parameters:
      str - The string to remove the unwanted substring from.
      unwanted - The unwanted substring.
      Returns:
      a string from which all instance of unwanted has been removed.
      Throws:
      IndexOutOfBoundsException
    • replaceAll

      public static String replaceAll(String str, String replaced, String replacing)
      Replace all literal occurrences of `replaced` in `str` with `replacing`. This preserves the original behavior for occurrences at the start or end.
      Parameters:
      str - the input string (must not be null)
      replaced - the substring to replace (must not be null)
      replacing - the replacement string (must not be null)
      Returns:
      a new string with all literal occurrences replaced
      Throws:
      NullPointerException - if any argument is null
      IndexOutOfBoundsException - if replaced is longer than str
    • delete

      public static String delete(String u, int i)
      method delete takes 2 arguments,the string to be modified and the index of the character to be deleted
      Parameters:
      u -
      i -
      Returns:
      the string after the character at index i has been removed
      Throws:
      StringIndexOutOfBoundsException
    • delete

      public static String delete(String u, String str)
      method delete takes 2 arguments,the string to be modified and the substring to be removed from it.
      Parameters:
      u - the string to be modified
      str - the substring to be removed from u
      Returns:
      the string after the first instance of the specified substring has been removed
      Throws:
      StringIndexOutOfBoundsException
    • delete

      public static String delete(String u, int i, int j)
      method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end. STRING.delete("Corinthian", 2,4)returns "Conthian"
      Parameters:
      u -
      i -
      j -
      Returns:
      Throws:
      StringIndexOutOfBoundsException
    • deleteCharsAfter

      public static String deleteCharsAfter(String str, int i, int num)
      method deleteCharsAfter takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end. STRING.delete("Corinthian", 2,4)returns "Conthian"
      Parameters:
      str - ..The original string
      i - ..The index at which we start deleting
      num - The number of characters to delete after the index.
      Returns:
      the resulting string after the chars between i and i+num-1 have been deleted.
      Throws:
      StringIndexOutOfBoundsException
    • isDouble

      public static boolean isDouble(String s)
      Checks if a string can be parsed as a double.
      Parameters:
      s - the string to check
      Returns:
      true if parsable as double, false otherwise
      Throws:
      NumberFormatException
    • isNumberComponent

      public static boolean isNumberComponent(String comp)
      Checks if a string is a valid number component. Valid components: digits, '.', 'E', '-', '+'
    • split

      public static ArrayList<String> split(String stringTosplit, String splittingObject) throws ArrayIndexOutOfBoundsException
      This is an optimized specialized substitute for String.split in the Java API. It runs about 10-20 times or more faster than the split method in the Java API and it returns an ArrayList of values, instead of an array. Splits a string on all instances of the splitting object
      Parameters:
      stringTosplit - The string to be split.
      splittingObject - The substring on which the string is to be split.
      Returns:
      an array containing substrings that the string has been split into.
      Throws:
      ArrayIndexOutOfBoundsException
    • splits

      public static String[] splits(String stringToSplit, String splittingObject)
      This is an highly optimized specialized substitute for String.split in the Java API. It runs about 40-100 times faster than the split method in the Java API and it returns an array, too. Splits a string on all instances of the splitting object
      Parameters:
      stringToSplit - The string to be split.
      splittingObject - The substring on which the string is to be split.
      Returns:
      an array containing substrings that the string has been split into.
    • splits

      public static String[] splits(String stringTosplit, String[] splittingObjects) throws NullPointerException
      This is an highly optimized specialized substitute for String.split in the Java API. It runs about 5-10 times faster than the split method in the Java API and it returns an Array object, too. If the array of splitting objects contains nothing or contains elements that are not found in the string, then an Array object containing the original string is returned. But if the array of splitting objects contains an empty string, it chops or slices the string into pieces, and so returns an Array object containing the individual characters of the string. Splits a string on all instances of the splitting object
      Parameters:
      stringTosplit - The string to be split.
      splittingObjects - An array containing substrings on which the string should be split.
      Returns:
      an array containing substrings that the string has been split into.
      Throws:
      NullPointerException - if the array of splitting objects contains a null value or is null.
    • isDigitChar

      public static boolean isDigitChar(char c)
      ////////////////////////////////////////////////////////////////////////////
    • isDigit

      public static boolean isDigit(String s)
      boolean Method isDigit can be used to check for single digits i.e 0-9.
      Parameters:
      s - the String to check.
      Returns:
      true if the string is a valid digit.
    • isDouble1

      public static boolean isDouble1(String a)
      Method isDouble1 is specially built for parsing number strings in my parser.Please do not use it for your own purposes. Its purpose is to detect already scanned number strings in a List object that contains many kinds of string objects
      Parameters:
      a -
      Returns:
      true if the string represents a number string( this in reality is true if the number has already being scanned and proven to be a valid number)
    • isWord

      public static boolean isWord(String a)
    • isLowerCaseWord

      public static boolean isLowerCaseWord(String s)
      method isLowerCaseWord takes one argument and that is the string whose case we wish to know.
      Parameters:
      s - The string to manipulate.
      Returns:
      true if the string is a lowercase letter
    • isUpperCaseWord

      public static boolean isUpperCaseWord(String s)
      method isUpperCaseWord takes one argument and that is the string whose case we wish to know.
      Parameters:
      s - The string to manipulate.
      Returns:
      true if the string is an uppercase letter
    • toUpperCase

      public static String toUpperCase(String m)
      method toUpperCase takes one argument only and that is the input string to be converted to upper case
      Parameters:
      m - the single length string to be converted to upper case
      Returns:
      the upper case version of the input
      Throws:
      StringIndexOutOfBoundsException
    • toLowerCase

      public static String toLowerCase(String m)
      method toLowerCase takes one argument only and that is input string to be converted to lower case
      Parameters:
      m - the single length string to be converted to lower case
      Returns:
      the lower case version of the input
      Throws:
      StringIndexOutOfBoundsException
    • reverse

      public static String reverse(String s)
      method reverse takes 1 argument and that is the string to be reversed
      Parameters:
      s - The string to be reversed.
      Returns:
      The reversed string.
    • replace

      public static String replace(String u, String u1, Integer i, Integer j) throws StringIndexOutOfBoundsException
      method replace takes 4 arguments,the string to be modified, the replacing string, the index at which replacement is to begin and the index where replacement ends plus one i.e replacement ends at index j-1. STRING.replace("Corinthian","The" 3,6)returns "CorThehians"
      Parameters:
      u - The string to manipulate.
      u1 - The replacing string
      i - Index at which to begin replacing
      j - Index at which replacement ends plus one
      Returns:
      A string in which the characters between index i and j-1 have been replaced with the replacing string
      Throws:
      StringIndexOutOfBoundsException
    • isEven

      public static boolean isEven(String s)
    • doubleToString

      public static String doubleToString(double num)
    • hasChars

      public static boolean hasChars(String s)
      Parameters:
      s - The String object to check.
      Returns:
      true if it contains at least one non-white space characters.
    • isEven

      public static boolean isEven(double a)
      Checks if a given number is even
      Parameters:
      a - the number
      Returns:
      true if a is even
    • isEven

      public static boolean isEven(float a)
      Checks if a given number is even
      Parameters:
      a - the number
      Returns:
      true if a is even
    • isEven

      public static boolean isEven(int a)
      Checks if a given number is even
      Parameters:
      a - the number
      Returns:
      true if a is even
    • main

      public static void main(String[] args)