public class ScriptString2
extends java.lang.Object
The underlying String2 class is Copyright (c) 2005 Robert Simons (CoHortSoftware@gmail.com). See the MIT/X-like license in com/cohort/util/LICENSE.txt.
Constructor and Description |
---|
ScriptString2()
|
Modifier and Type | Method and Description |
---|---|
static boolean |
allDigits(java.lang.String s)
0..9.
|
static java.lang.String |
annotatedString(java.lang.String s)
This converts non-isPrintable characters to "[#]".
|
static java.lang.String |
arrayToCSSVString(java.lang.Object value)
This returns a nice String representation of the attribute value
(which should be a String or an array of primitives).
|
static int |
binaryFindClosest(java.lang.String[] sar,
java.lang.String s)
Find the closest element to s in an ascending sorted array.
|
static int |
binaryFindFirstGE(java.lang.String[] sar,
java.lang.String s)
Find the first element which is >= s in an ascending sorted array.
|
static int |
binaryFindLastLE(java.lang.String[] sar,
java.lang.String s)
Find the last element which is <= s in an ascending sorted array.
|
static java.lang.String |
camelCaseToTitleCase(java.lang.String s)
This converts "camelCase99String" to "Camel Case 99 String"
|
static int |
caseInsensitiveIndexOf(java.lang.Object[] ar,
java.lang.String s)
This finds the first element in Object[]
where ar[i].toString().toLowerCase() equals to s.toLowerCase().
|
static java.lang.String |
center(java.lang.String s,
int length)
Returns a String 'length' long, with 's' centered
(using spaces as the added characters) within the resulting String.
|
static java.lang.String |
charToJsonString(char ch,
int firstUEncodedChar,
boolean encodeNewline)
This encodes one char to the Json encoding.
|
static java.lang.String |
combineSpaces(java.lang.String s)
Returns a string where all cases of more than one space are
replaced by one space.
|
static java.lang.String |
commonUnicodeToPlainText(java.lang.String s)
|
static int |
countAll(java.lang.String s,
char findS)
This counts all occurrences of findS in s.
|
static int |
countAll(java.lang.String s,
java.lang.String findS)
This counts all occurrences of findS in s.
|
static double[] |
csvToDoubleArray(java.lang.String csv)
This converts a comma-separated-value String into a double[].
|
static int[] |
csvToIntArray(java.lang.String csv)
This converts a comma-separated-value String into an int[].
|
static java.lang.String |
differentLine(java.lang.String oldS,
java.lang.String newS)
Given two strings with internal newlines, oldS and newS, this a message
indicating where they differ.
|
static java.lang.String |
encodeFileNameSafe(java.lang.String s)
This is different from String2.modifyToBeFileNameSafe --
this encodes non-fileNameSafe characters so little or no information is lost.
|
static java.lang.String |
encodeMatlabNameSafe(java.lang.String s)
This is like encodeFileNameSafe, but further restricts the name to
first character must be A-Z, a-z.
|
static java.lang.String[] |
extractAllCaptureGroupsAsStringArray(java.lang.String s,
java.lang.String regex,
int captureGroupNumber)
This repeatedly finds the regex and extracts the specified captureGroup.
|
static java.lang.String[] |
extractAllRegexes(java.lang.String s,
java.lang.String regex)
This returns all the sections of s that match regex.
|
static java.lang.String |
extractCaptureGroup(java.lang.String s,
java.lang.String regex,
int captureGroupNumber)
This returns the specified capture group from s.
|
static java.lang.String |
extractRegex(java.lang.String s,
java.lang.String regex,
int fromIndex)
This returns the first section of s (starting at fromIndex)
which matches regex.
|
static int |
findInvalidUnicode(java.lang.String s,
java.lang.String alsoOK)
This returns the index of the first non-Unicode character.
|
static int |
findNth(java.lang.String s,
char findS,
int nth)
This returns the index of the nth occurrence of findS in s.
|
static java.lang.String |
findPrefix(java.lang.String[] prefixes,
java.lang.String longerString,
int startAt)
This is like whichPrefix, but returns the found prefix (or null).
|
static int |
findWholeWord(java.lang.String s,
java.lang.String word)
This finds (case-sensitive) the first whole word instance of 'word' in s.
|
static java.lang.String |
fromJson(java.lang.String s)
This returns the unJSON version of a JSON string
(surrounding "'s (if any) are removed and \\, \f, \n, \r, \t, \/, and \" are unescaped).
|
static java.lang.String |
fromJsonNotNull(java.lang.String s)
This is like the other fromJson, but returns "" instead of null.
|
static char |
fromNccsvChar(java.lang.String s)
This converts an NCCSV encoded char to a true char
(surrounding "'s and ''s (if any) are removed and \\, \f, \n, \r, \t, \/, and \" are unescaped).
|
static java.lang.String |
fromNccsvString(java.lang.String s)
This converts an NCCSV string to a true string
(surrounding "'s (if any) are removed and \\, \f, \n, \r, \t, \/, and \" are unescaped).
|
static java.lang.String |
genEFormat10(double d)
This returns the number formatted with up to 10 digits to the left and right of
the decimal and trailing decimal 0's removed.
|
static java.lang.String |
genEFormat6(double d)
This returns the number formatted with up to 6 digits to the left and right of
the decimal and trailing decimal 0's removed.
|
static java.lang.String |
genHTMLFormat10(double d)
This is like genEFormat10, but the scientific notation format
is, e.g., 8.9509244321x10-5.
|
static java.lang.String |
genHTMLFormat6(double d)
This is like genEFormat6, but the scientific notation format
is, e.g., 8.954321x10-5.
|
static java.lang.String |
genX10Format10(double d)
This is like genEFormat10, but the scientific notation format
is, e.g., 8.9509484321x10^-5.
|
static java.lang.String |
genX10Format6(double d)
This is like genEFormat6, but the scientific notation format
is, e.g., 8.954321x10^-5.
|
static int |
getNMatchingCharacters(java.lang.String s1,
java.lang.String s2)
This determines the number of initial characters that match.
|
static java.lang.String |
ifJsonFromJson(java.lang.String s)
If the String is surrounded by ", this returns fromJson(s), else it returns s.
|
static java.lang.String |
ifSomethingConcat(java.lang.String a,
java.lang.String separator,
java.lang.String b)
This cleverly concatenates the 2 strings (with separator, as appropriate).
|
static int |
indexOf(char[] cArray,
char c)
Finds the first instance of c in cArray.
|
static int |
indexOf(char[] cArray,
char c,
int fromIndex)
Finds the first instance of c at or after fromIndex (0..
|
static int |
indexOf(double[] dArray,
double d)
Finds the first instance of d in dArray
(tested with Math2.almostEqual5).
|
static int |
indexOf(double[] dArray,
double d,
int fromIndex)
Finds the first instance of d at or after fromIndex (0..
|
static int |
indexOf(int[] iArray,
int i)
Finds the first instance of i in iArray.
|
static int |
indexOf(int[] iArray,
int i,
int fromIndex)
Finds the first instance of i at or after fromIndex (0..
|
static int |
indexOf(java.lang.Object[] ar,
java.lang.String s)
This finds the first element in Object[]
where the ar[i].toString value equals to s.
|
static int |
indexOf(java.lang.Object[] ar,
java.lang.String s,
int startAt)
This finds the first element in Object[] (starting at element startAt)
where the ar[i].toString value equals s.
|
static int |
indexOf(java.lang.String s,
java.lang.String car,
int fromIndex)
This indexOf is a little different: it finds the first instance in s of any char
in car.
|
static int |
indexOfChar(java.lang.String s,
char[] car,
int fromIndex)
This indexOf is a little different: it finds the first instance in s of any char
in car.
|
static int |
indexOfIgnoreCase(java.lang.String s,
java.lang.String find)
Finds the first instance of 'find' at or after fromIndex (0..), ignoring case.
|
static int |
indexOfIgnoreCase(java.lang.String s,
java.lang.String find,
int fromIndex)
Finds the first instance of 'find' at or after fromIndex (0..), ignoring case.
|
static int |
indexOfObject(java.lang.Object[] ar,
java.lang.Object o)
A variant of indexOfObject() that uses startAt=0.
|
static int |
indexOfObject(java.lang.Object[] ar,
java.lang.Object o,
int startAt)
This finds the first element in Object[] (starting at element startAt)
where ar[i]==o.
|
static boolean |
isAsciiLetter(int c)
This returns true for A..Z, a..z.
|
static boolean |
isAsciiPrintable(int ch)
returns true if ch is 32..126.
|
static boolean |
isAsciiPrintable(java.lang.String s)
Returns true if all of the characters in s are 32..126
|
static boolean |
isDigit(int c)
0..9.
|
static boolean |
isDigitLetter(int c)
Determines if the character is a digit or a letter.
|
static boolean |
isDoubleTrouble(java.lang.String s)
DON'T USE THIS; RELY ON THE FIXES AVAILABLE FOR JAVA:
EITHER THE LATEST VERSION OF JAVA OR THE
JAVA UPDATER TO FIX THE BUG ON EXISTING OLDER JAVA INSTALLATIONS
https://www.oracle.com/technetwork/java/javase/fpupdater-tool-readme-305936.html
|
static boolean |
isEmailAddress(java.lang.String email)
This indicates if 'email' is a valid email address.
|
static boolean |
isFileNameSafe(char ch)
This indicates if ch is a file-name-safe character (A-Z, a-z, 0-9, _, -, or .).
|
static boolean |
isFileNameSafe(java.lang.String s)
This indicates if s has length >= 1 and
has just file-name-safe characters (0-9, A-Z, a-z, _, -, .).
|
static boolean |
isHexDigit(int c)
0..9, a..f, A..F
Hex numbers are 0x followed by hexDigits.
|
static boolean |
isHexString(java.lang.String s)
Returns true if all of the characters in s are hex digits.
|
static boolean |
isIDFirstLetter(int c)
First letters for identifiers (e.g., variable names, method names) can be
all isLetter()'s plus $ and _.
|
static boolean |
isIso8859(java.lang.String s)
This returns true if the string contains only ISO 8859-1 characters (i.e., 0 -
255).
|
static boolean |
isJsonpNameSafe(java.lang.String s)
This tests if s is a valid jsonp function name.
|
static boolean |
isLetter(int c)
This includes hiASCII/ISO Latin 1/ISO 8859-1, but not extensive unicode
characters.
|
static boolean |
isNumber(java.lang.String s)
This tries to quickly determine if the string is a correctly
formatted number (including decimal, hexadecimal, octal, and "NaN" (any case)).
|
static boolean |
isPrintable(int ch)
This indicates if ch is printable with System.err.println() and
Graphics.drawString(); hence, it is a subset of 0..255.
|
static boolean |
isPrintable(java.lang.String s)
Returns true if all of the characters in s are printable
|
static boolean |
isRemote(java.lang.String dir)
This returns true if the dir starts with http://, https://, ftp://, sftp://,
or smb://.
|
static boolean |
isSomething(java.lang.String s)
This returns true if s isn't null and s.trim().length() > 0.
|
static boolean |
isSomething2(java.lang.String s)
This returns true if s isn't null, "", "-", "null", "nd", "N/A", "...", "???",
etc.
|
static boolean |
isUrl(java.lang.String url)
This indicates if 'url' is probably a valid url.
|
static boolean |
isVariableNameSafe(java.lang.String s)
This tests if s is a valid variableName:
first character must be (iso8859Letter|_).
|
static boolean |
isWhite(int c)
Whitespace characters are u0001 ..
|
static double[] |
justFiniteValues(double[] dar)
This returns a double[] with just the finite values from the original
array.
|
static int[] |
justFiniteValues(int[] iar)
This returns an int[] with just the non-Integer.MAX_VALUE values from the
original
array.
|
static java.lang.String |
justPrintable(java.lang.String s)
This returns the string with all non-isPrintable characters removed.
|
static java.lang.String |
left(java.lang.String s,
int length)
Returns a String 'length' long, with 's' left-justified
(using spaces as the added characters) within the resulting String.
|
static int |
lineContaining(java.lang.Object[] ar,
java.lang.String s)
This finds the first element in Object[]
where the ar[i].toString value contains the substring s.
|
static int |
lineContaining(java.lang.Object[] ar,
java.lang.String s,
int startAt)
This finds the first element in Object[] (starting at element startAt)
where the ar[i].toString value contains the substring s.
|
static int |
lineContainingIgnoreCase(java.lang.Object[] ar,
java.lang.String s,
int startAt)
This finds the first element in Object[] (starting at element startAt)
where the ar[i].toString value contains the substring s (ignoring
the case of ar and s).
|
static int |
lineStartsWith(java.lang.Object[] ar,
java.lang.String s)
This finds the first element in Object[] (starting at element 0)
where the ar[i].toString value starts with s.
|
static int |
lineStartsWith(java.lang.Object[] ar,
java.lang.String s,
int startAt)
This finds the first element in Object[] (starting at element startAt)
where the ar[i].toString value starts with s.
|
static int |
lineStartsWithIgnoreCase(java.lang.Object[] ar,
java.lang.String s)
This variant of lineStartsWith startsAt index=0.
|
static int |
lineStartsWithIgnoreCase(java.lang.Object[] ar,
java.lang.String s,
int startAt)
This is like lineStartsWith, but ignores case.
|
static boolean |
looselyContains(java.lang.String s,
java.lang.String find)
This goes beyond indexOfIgnoreCase by looking after punctuation removed.
|
static boolean |
looselyEquals(java.lang.String s1,
java.lang.String s2)
This goes beyond equalsIgnoreCase by looking after punctuation removed.
|
static java.lang.String |
makeString(char ch,
int length)
This makes a new String of specified length, filled with ch.
|
static java.lang.String |
makeValidUnicode(java.lang.String s,
java.lang.String alsoOK)
This makes s valid Unicode by converting invalid characters (e.g., #128)
with \\uhhhh (literally 2 backslashes, so no info is lost).
|
static java.lang.String |
max(java.lang.String s1,
java.lang.String s2)
This returns the string which sorts higher.
|
static java.lang.String |
md5Hex(java.lang.String password)
This returns the MD5 hash digest of stringToUtf8Bytes(password) as a String of 32
lowercase hex digits.
|
static java.lang.String |
md5Hex12(java.lang.String password)
This returns the last 12 hex digits from md5Hex (or null if md5 is null),
broken into 3 blocks of 4 digits, separated by '_'.
|
static java.lang.String |
min(java.lang.String s1,
java.lang.String s2)
This returns the string which sorts lower.
|
static java.lang.String |
modifyToBeASCII(java.lang.String s)
This converts the string to plain ascii (0..127).
|
static java.lang.String |
modifyToBeFileNameSafe(java.lang.String s)
This returns the string with just file-name-safe characters (0-9, A-Z, a-z, _, -,
.).
|
static java.lang.String |
modifyToBeVariableNameSafe(java.lang.String s)
This is like modifyToBeFileNameSafe, but restricts the name to:
first character must be (iso8859Letter|_).
|
static java.lang.String |
noLongerThan(java.lang.String s,
int max)
This returns a string no more than max characters long, throwing away the excess.
|
static java.lang.String |
noLongerThanDots(java.lang.String s,
int max)
This is like noLongerThan, but if truncated, s.substring(0, max-3) + "..." is
returned.
|
static java.lang.String |
noLongLines(java.lang.String s,
int maxLength,
java.lang.String spaces)
If lines in s are >=maxLength characters, this inserts "\n"+spaces at the
previous non-DigitLetter + DigitLetter; or if none, this inserts "\n"+spaces at maxLength.
|
static java.lang.String |
noLongLinesAtSpace(java.lang.String s,
int maxLength,
java.lang.String spaces)
This is like noLongLines, but will only break at spaces.
|
static boolean |
parseBoolean(java.lang.String s)
This converts a string to a boolean.
|
static byte |
parseBooleanToInt(java.lang.String s)
This converts a string to a boolean and then an int.
|
static double |
parseDouble(java.lang.String s)
Convert a string to a double.
|
static float |
parseFloat(java.lang.String s)
Parse as a float with either "." or "," as the decimal point.
|
static int |
parseInt(java.lang.String s)
Convert a string to an int.
|
static int |
parseInt(java.lang.String s,
int def)
Like parseInt(s), but returns def if error).
|
static long |
parseLong(java.lang.String s)
This converts String representation of a long.
|
static java.lang.String |
passwordDigest(java.lang.String algorithm,
java.lang.String password)
This returns the hash digest of stringToUtf8Bytes(password) as a String of
lowercase hex digits.
|
static java.lang.String |
periodSpaceConcat(java.lang.String a,
java.lang.String b)
This cleverly concatenates the 2 strings (with "", ".
|
static java.lang.String |
quoteParameterIfNeeded(java.lang.String s)
For command line parameters, this returns toJson(s) if the string is empty or
contains
special characters or single or double quotes or backslash; otherwise it return s.
|
static java.lang.String |
removeLeading(java.lang.String s,
char ch)
This removes leading ch's.
|
static java.lang.String[] |
removeNull(java.lang.String[] sar)
This returns a String[] with just non-null strings
from the original array.
|
static java.lang.String[] |
removeNullOrEmpty(java.lang.String[] sar)
This returns a String[] with just non-null and non-"" strings
from the original array.
|
static java.lang.String |
repeatedlyReplaceAll(java.lang.String s,
java.lang.String oldS,
java.lang.String newS,
boolean ignoreCase)
This repeatedly replaces all oldS with newS.
|
static java.lang.String |
replaceAll(java.lang.String s,
char oldCh,
char newCh)
Returns a string where all occurences of oldCh have
been replaced with newCh.
|
static java.lang.String |
replaceAll(java.lang.String s,
java.lang.String oldS,
java.lang.String newS)
Returns a string where all occurences of oldS have
been replaced with newS.
|
static java.lang.String |
replaceAllIgnoreCase(java.lang.String s,
java.lang.String oldS,
java.lang.String newS)
Returns a string where all occurences of oldS have
been replaced with newS.
|
static java.lang.String |
right(java.lang.String s,
int length)
Returns a String 'length' long, with 's' right-justified
(using spaces as the added characters) within the resulting String.
|
static double |
roundingParseInt(java.lang.String s)
Convert a string to an int, with rounding.
|
static java.lang.String |
simpleMatlabNameSafe(java.lang.String s)
This is like encodeMatlabNameSafe, but simpler and won't always retain all the
info.
|
static java.lang.String[] |
split(java.lang.String s,
char separator)
This splits the string at the specified character.
|
static java.lang.String[] |
splitNoTrim(java.lang.String s,
char separator)
This splits the string at the specified character.
|
static java.lang.String |
stringStartsWith(java.lang.Object[] ar,
java.lang.String s)
This returns the first element in Object[] (starting at element 0)
where the ar[i].toString value starts with s.
|
static byte[] |
stringToUtf8Bytes(java.lang.String s)
This returns the UTF-8 encoding of the string (or null if trouble).
|
static java.lang.String |
substitute(java.lang.String msg,
java.lang.String s0,
java.lang.String s1,
java.lang.String s2)
This replaces "{0}", "{1}", and "{2}" in msg with s0, s1, s2.
|
static java.lang.String |
to0xHexString(int i,
int nHexDigits)
This returns the int formatted as a 0x hex String with at least nHexDigits,
e.g., 0x00FF00.
|
static byte[] |
toByteArray(java.lang.String s)
This extracts the lower 8 bits of each char to form a
byte array.
|
static java.lang.String |
toCSSVString(boolean[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(byte[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(char[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(double[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(float[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(int[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(long[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSSVString(java.lang.Object[] ar)
Generates a Comma-Space-Separated-Value (CSSV) string.
|
static java.lang.String |
toCSSVString(short[] ar)
This generates a Comma-Space-Separated-Value (CSSV) String from the array.
|
static java.lang.String |
toCSVString(java.lang.Object[] ar)
This returns a CSV (not CSSV) String.
|
static double[] |
toDoubleArray(java.lang.Object[] oar)
This converts an Object[] (for example, where objects are Strings or
Doubles) into a double[].
|
static float[] |
toFloatArray(java.lang.Object[] oar)
This converts an Object[] (for example, where objects are Strings or
Floats) into a float[].
|
static java.lang.String |
toHexCSSVString(byte[] ar)
This generates a hexadecimal Comma-Space-Separated-Value (CSSV) String from the
array.
|
static java.lang.String |
toHexCSSVString(int[] ar)
This generates a hexadecimal Comma-Space-Separated-Value (CSSV) String from the
array.
|
static java.lang.String |
toHexCSSVString(short[] ar)
This generates a hexadecimal Comma-Space-Separated-Value (CSSV) String from the
array.
|
static int[] |
toIntArray(java.lang.Object[] oar)
This converts an Object[] (for example, where objects are Strings or
Integers) into an int[].
|
static char |
toIso88591Char(char ch)
This converts the char to an ISO-8859-1 (ISO_8859_1) char.
|
static char[] |
toIso88591Chars(char[] car)
This converts the chars to ISO-8859-1 (ISO_8859_1) chars.
|
static java.lang.String |
toJson(double d)
This makes a JSON version of a number.
|
static java.lang.String |
toJson(float f)
This makes a JSON version of a float.
|
static java.lang.String |
toJson(java.lang.String s)
This makes a JSON version of a string
(\\, \f, \n, \r, \t and \" are escaped with a backslash character
and double quotes are added before and after).
|
static java.lang.String |
toJson(java.lang.String s,
int firstUEncodedChar)
This makes a JSON version of a string
(\\, \f, \n, \r, \t and \" are escaped with a backslash character
and double quotes are added before and after).
|
static java.lang.String |
toJson(java.lang.String s,
int firstUEncodedChar,
boolean encodeNewline)
This is a variant of toJson that lets you encode newlines or not.
|
static java.lang.String |
toJson65536(java.lang.String s)
This variant doesn't encode high characters.
|
static java.lang.String |
toJsonArray(java.lang.String[] sa)
The converts a string[] into a JSON array of strings.
|
static java.lang.String[] |
tokenize(java.lang.String s)
This converts a multiple-space-separated string into a String[] of separate
tokens.
|
static java.lang.String |
toNccsvAttString(java.lang.String s)
This encodes one String as an NCCSV att String, with surrounding double quotes
only if necessary.
|
static java.lang.String |
toNccsvChar(char ch)
This encodes one char for an NCCSV char or String, without surrounding quotes.
|
static java.lang.String |
toNccsvDataString(java.lang.String s)
This encodes one String as an NCCSV data String, with surrounding double quotes
only if necessary.
|
static java.lang.String |
toNewlineString(double[] ar)
This generates a newline-separated (always '\n') String from the array.
|
static java.lang.String |
toNewlineString(int[] ar)
This generates a newline-separated (always '\n') String from the array.
|
static java.lang.String |
toNewlineString(java.lang.Object[] ar)
Generates a newline-separated string, with a newline at the end.
|
static int[] |
toRational(double d)
This converts a double to a rational number (m * 10^t).
|
static java.lang.String |
toSentenceCase(java.lang.String s)
This changes the character's case to sentence case
(first letter and first letter after each period capitalized).
|
static java.lang.String |
toSSVString(java.lang.Object[] ar)
Generates a space-separated-value string.
|
static java.lang.String[] |
toStringArray(java.lang.Object[] aa)
This converts an Object[] into a String[].
|
static java.lang.String |
toSVString(java.lang.Object[] ar,
java.lang.String separator,
boolean finalSeparator)
This is used at a low level to generate a
'separator'-separated-value string (without newlines)
with the element.toString()'s from the array.
|
static java.lang.String |
toTitleCase(java.lang.String s)
This changes the characters case to title case (only letters after non-letters
are
capitalized).
|
static java.lang.String |
toSVString(java.lang.String s)
This encodes special characters in s if needed so that
s can be stored as an item in a tsv string.
|
static java.lang.String |
toVariableName(java.lang.String s)
This suggests a camel-case variable name.
|
static java.lang.String |
trimEnd(java.lang.String s)
This trims just the end of the string.
|
static java.lang.String |
trimStart(java.lang.String s)
This trims just the start of the string.
|
static java.lang.String |
utf8BytesToString(byte[] bar)
This returns a string from the UTF-8 encoded byte[] (or ERROR if trouble).
|
static int |
whichPrefix(java.lang.String[] prefixes,
java.lang.String longerString,
int startAt)
This finds the first element in prefixes (starting at element startAt)
where the longerString starts with prefixes[i].
|
static int |
whichSuffix(java.lang.String[] suffixes,
java.lang.String longerString,
int startAt)
This finds the first element in suffixes (starting at element startAt)
where the longerString ends with suffixes[i].
|
static int |
whichWord(java.lang.String longerString,
java.lang.String[] words)
This tries to find the first one of the words in the longerString.
|
static java.lang.String |
whitespacesToSpace(java.lang.String s)
|
static java.lang.String |
zeroPad(java.lang.String number,
int nDigits)
This adds 0's to the left of the string until there are nDigits
to the left of the decimal point (or nDigits total if there isn't
a decimal point).
|
public static java.lang.String max(java.lang.String s1, java.lang.String s2)
s1
- s2
- public static java.lang.String min(java.lang.String s1, java.lang.String s2)
s1
- s2
- public static java.lang.String makeString(char ch, int length)
ch
- the character to fill the stringlength
- the length of the stringpublic static java.lang.String right(java.lang.String s, int length)
s
- is the string to be right-justified.length
- is desired length of the resulting string.public static java.lang.String left(java.lang.String s, int length)
s
- is the string to be left-justified.length
- is desired length of the resulting string.public static java.lang.String center(java.lang.String s, int length)
s
- is the string to be centered.length
- is desired length of the resulting string.public static java.lang.String noLongerThan(java.lang.String s, int max)
s
- max
- public static java.lang.String noLongerThanDots(java.lang.String s, int max)
s
- max
- public static java.lang.String annotatedString(java.lang.String s)
s
- the stringpublic static int getNMatchingCharacters(java.lang.String s1, java.lang.String s2)
s1
- s2
- public static int indexOfIgnoreCase(java.lang.String s, java.lang.String find)
s
- find
- public static int indexOfIgnoreCase(java.lang.String s, java.lang.String find, int fromIndex)
s
- find
- fromIndex
- public static boolean looselyContains(java.lang.String s, java.lang.String find)
s
- find
- public static boolean looselyEquals(java.lang.String s1, java.lang.String s2)
s1
- s2
- public static int findWholeWord(java.lang.String s, java.lang.String word)
word
- must be a simple word (without regex special characters)public static java.lang.String extractRegex(java.lang.String s, java.lang.String regex, int fromIndex)
s
- the source String.regex
- the regular expression, see java.util.regex.Pattern.fromIndex
- the starting index in sjava.lang.RuntimeException
- if troublepublic static java.lang.String[] extractAllRegexes(java.lang.String s, java.lang.String regex)
s
- the source Stringregex
- the regular expression, see java.util.regex.Pattern.
Note that you often want to use the "reluctant" qualifiers
which match as few chars as possible (e.g., ??, *?, +?)
not the "greedy" qualifiers
which match as many chars as possible (e.g., ?, *, +).java.lang.RuntimeException
- if troublepublic static java.lang.String[] extractAllCaptureGroupsAsStringArray(java.lang.String s, java.lang.String regex, int captureGroupNumber)
s
- the source Stringregex
- the regular expression, see java.util.regex.Pattern.
Note that you often want to use the "reluctant" qualifiers
which match as few chars as possible (e.g., ??, *?, +?)
not the "greedy" qualifiers
which match as many chars as possible (e.g., ?, *, +).public static java.lang.String extractCaptureGroup(java.lang.String s, java.lang.String regex, int captureGroupNumber)
s
- the source Stringregex
- the regular expression which probably matches part of s. See
java.util.regex.Pattern.captureGroupNumber
- the number of the capture group (0 for entire regex,
1 for first capture group, 2 for second, etc.)java.lang.RuntimeException
- if trouble, e.g., invalid regex syntaxpublic static int indexOf(int[] iArray, int i, int fromIndex)
iArray
- i
- the int you want to findfromIndex
- the index number of the position to start the searchpublic static int indexOf(int[] iArray, int i)
iArray
- i
- the int you want to findpublic static int indexOf(char[] cArray, char c, int fromIndex)
cArray
- c
- the char you want to findfromIndex
- the index number of the position to start the searchpublic static int indexOf(char[] cArray, char c)
cArray
- c
- the char you want to findpublic static int indexOfChar(java.lang.String s, char[] car, int fromIndex)
s
- a stringcar
- the chars you want to find any offromIndex
- the index number of the position to start the searchpublic static int indexOf(java.lang.String s, java.lang.String car, int fromIndex)
s
- a stringcar
- the chars you want to find any offromIndex
- the index number of the position to start the searchpublic static int indexOf(double[] dArray, double d, int fromIndex)
dArray
- d
- the double you want to findfromIndex
- the index number of the position to start the searchpublic static int whichWord(java.lang.String longerString, java.lang.String[] words)
public static int indexOf(double[] dArray, double d)
dArray
- d
- the double you want to findpublic static final boolean isAsciiLetter(int c)
c
- a charpublic static final boolean isLetter(int c)
c
- a charpublic static final boolean isIDFirstLetter(int c)
c
- a charpublic static final boolean isHexDigit(int c)
c
- a charpublic static final boolean isHexString(java.lang.String s)
public static final boolean isDigit(int c)
c
- a charpublic static final boolean allDigits(java.lang.String s)
s
- a stringpublic static final boolean isDigitLetter(int c)
c
- a charpublic static final boolean isNumber(java.lang.String s)
This may not be perfect. In the future, this may be changed to be perfect. That shouldn't affect its use.
s
- usually already trimmed, since any space in s will return false.public static final boolean isWhite(int c)
c
- a charpublic static final boolean isPrintable(int ch)
ch
- a charpublic static final boolean isPrintable(java.lang.String s)
public static final boolean isAsciiPrintable(int ch)
public static final boolean isAsciiPrintable(java.lang.String s)
public static java.lang.String justPrintable(java.lang.String s)
s
- public static java.lang.String modifyToBeASCII(java.lang.String s)
s
- public static boolean isFileNameSafe(char ch)
ch
- public static boolean isEmailAddress(java.lang.String email)
email
- a possible email addresspublic static boolean isUrl(java.lang.String url)
url
- a possible urlpublic static boolean isRemote(java.lang.String dir)
public static boolean isFileNameSafe(java.lang.String s)
s
- a string, usually a file namepublic static java.lang.String modifyToBeFileNameSafe(java.lang.String s)
s
- If s is null, this returns "_null".
If s is "", this returns "_".public static boolean isVariableNameSafe(java.lang.String s)
s
- a possible variable namepublic static boolean isJsonpNameSafe(java.lang.String s)
s
- a possible jsonp function namepublic static java.lang.String modifyToBeVariableNameSafe(java.lang.String s)
s
- public static int countAll(java.lang.String s, java.lang.String findS)
s
- the source stringfindS
- the string to be searched forpublic static int countAll(java.lang.String s, char findS)
s
- the source stringfindS
- the char to be searched forpublic static int findNth(java.lang.String s, char findS, int nth)
s
- the source stringfindS
- the char to be searched fornth
- 1+public static java.lang.String repeatedlyReplaceAll(java.lang.String s, java.lang.String oldS, java.lang.String newS, boolean ignoreCase)
public static java.lang.String replaceAll(java.lang.String s, java.lang.String oldS, java.lang.String newS)
s
- the main stringoldS
- the string to be searched fornewS
- the string to replace oldSjava.lang.RuntimeException
- if s is null.public static java.lang.String replaceAllIgnoreCase(java.lang.String s, java.lang.String oldS, java.lang.String newS)
s
- the main stringoldS
- the string to be searched fornewS
- the string to replace oldSpublic static java.lang.String combineSpaces(java.lang.String s)
s
- public static java.lang.String whitespacesToSpace(java.lang.String s)
public static java.lang.String replaceAll(java.lang.String s, char oldCh, char newCh)
public static java.lang.String commonUnicodeToPlainText(java.lang.String s)
public static java.lang.String zeroPad(java.lang.String number, int nDigits)
number
- a positive number. This doesn't handle negative numbers.nDigits
- the desired number of digits to the left of the decimal point
(or total, if no decimal point)public static java.lang.String toJsonArray(java.lang.String[] sa)
sa
- public static java.lang.String toJson(float f)
f
- public static java.lang.String toJson(double d)
d
- public static java.lang.String toJson(java.lang.String s)
s
- public static java.lang.String toJson65536(java.lang.String s)
s
- public static java.lang.String toJson(java.lang.String s, int firstUEncodedChar)
s
- The String to be encoded.firstUEncodedChar
- The first char to be \\uhhhh encoded,
commonly 127, 256, or 65536.public static java.lang.String toJson(java.lang.String s, int firstUEncodedChar, boolean encodeNewline)
s
- The String to be encoded.firstUEncodedChar
- The first char to be \\uhhhh encoded,
commonly 127, 256, or 65536.public static java.lang.String charToJsonString(char ch, int firstUEncodedChar, boolean encodeNewline)
public static java.lang.String fromJsonNotNull(java.lang.String s)
public static java.lang.String ifJsonFromJson(java.lang.String s)
public static java.lang.String fromJson(java.lang.String s)
s
- it may be enclosed by "'s, or not.public static char fromNccsvChar(java.lang.String s)
s
- it may be enclosed by "'s and ''s, or not.public static java.lang.String fromNccsvString(java.lang.String s)
s
- it may be enclosed by "'s, or not.public static java.lang.String toNccsvChar(char ch)
public static java.lang.String toNccsvDataString(java.lang.String s)
public static java.lang.String toNccsvAttString(java.lang.String s)
public static java.lang.String toSVString(java.lang.String s)
public static java.lang.String substitute(java.lang.String msg, java.lang.String s0, java.lang.String s1, java.lang.String s2)
msg
- a string which may contain "{0}", "{1}", and/or "{2}".s0
- the first substitution string. If null, that substitution
won't be attempted.s1
- the second substitution string. If null, that substitution
won't be attempted.s2
- the third substitution string. If null, that substitution
won't be attempted.public static java.lang.String toCSVString(java.lang.Object[] ar)
public static java.lang.String toCSSVString(java.lang.Object[] ar)
CHANGED: before 2011-03-06, this didn't do anything special for strings with internal commas or quotes. Now it uses toJson for that string.
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of objectspublic static java.lang.String toSSVString(java.lang.Object[] ar)
WARNING: This is simplistic. It doesn't do anything special for strings with internal spaces.
ar
- an array of objects
(for an ArrayList or Vector, use o.toArray())public static java.lang.String toNewlineString(java.lang.Object[] ar)
WARNING: This is simplistic. It doesn't do anything special for strings with internal newlines.
ar
- an array of objects
(for an ArrayList or Vector, use o.toArray())public static java.lang.String toSVString(java.lang.Object[] ar, java.lang.String separator, boolean finalSeparator)
ar
- an array of objects
(for an ArrayList or Vector, use o.toArray())separator
- the separator stringfinalSeparator
- if true, a separator will be added to the
end of the resulting string (if it isn't "").public static java.lang.String toCSSVString(boolean[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of booleanpublic static java.lang.String toCSSVString(byte[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of bytespublic static java.lang.String toCSSVString(char[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of charpublic static java.lang.String to0xHexString(int i, int nHexDigits)
public static java.lang.String toHexCSSVString(byte[] ar)
CHANGED: before 2011-09-04, this was called toHexCSVString.
ar
- an array of bytespublic static java.lang.String toCSSVString(short[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of shortspublic static java.lang.String toHexCSSVString(short[] ar)
CHANGED: before 2011-09-04, this was called toHexCSVString.
ar
- an array of shortpublic static java.lang.String toCSSVString(int[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of intspublic static java.lang.String toHexCSSVString(int[] ar)
CHANGED: before 2011-09-04, this was called toHexCSVString.
ar
- an array of intspublic static java.lang.String toCSSVString(long[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of longspublic static java.lang.String toCSSVString(float[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of floatpublic static java.lang.String toCSSVString(double[] ar)
CHANGED: before 2011-09-04, this was called toCSVString.
ar
- an array of doublepublic static java.lang.String toNewlineString(int[] ar)
ar
- an array of intspublic static java.lang.String toNewlineString(double[] ar)
ar
- an array of doublepublic static java.lang.String[] toStringArray(java.lang.Object[] aa)
aa
- public static java.lang.String arrayToCSSVString(java.lang.Object value)
CHANGED: before 2011-09-04, this was called toCSVString.
value
- public static byte[] toByteArray(java.lang.String s)
s
- a Stringpublic static int indexOfObject(java.lang.Object[] ar, java.lang.Object o, int startAt)
ar
- the array of Objectso
- the String to be foundstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.
If startAt >= ar.length, this returns -1.public static int indexOfObject(java.lang.Object[] ar, java.lang.Object o)
public static int indexOf(java.lang.Object[] ar, java.lang.String s)
ar
- the array of Objects (Strings?)s
- the String to be foundpublic static int indexOf(java.lang.Object[] ar, java.lang.String s, int startAt)
ar
- the array of Objectss
- the String to be foundstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.
If startAt >= ar.length, this returns -1.public static int caseInsensitiveIndexOf(java.lang.Object[] ar, java.lang.String s)
ar
- the array of Objectss
- the String to be foundpublic static int lineContaining(java.lang.Object[] ar, java.lang.String s)
ar
- the array of objectss
- the String to be foundpublic static int lineContaining(java.lang.Object[] ar, java.lang.String s, int startAt)
ar
- the array of objectss
- the String to be foundstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static int lineContainingIgnoreCase(java.lang.Object[] ar, java.lang.String s, int startAt)
ar
- the array of objectss
- the String to be foundstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static java.lang.String stringStartsWith(java.lang.Object[] ar, java.lang.String s)
ar
- the array of objectss
- the String to be foundpublic static int lineStartsWith(java.lang.Object[] ar, java.lang.String s)
ar
- the array of objectss
- the String to be foundpublic static int lineStartsWith(java.lang.Object[] ar, java.lang.String s, int startAt)
ar
- the array of objectss
- the String to be foundstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static int lineStartsWithIgnoreCase(java.lang.Object[] ar, java.lang.String s)
ar
- the array of objects, e.g., including LATITUDEs
- the String to be found, e.g., Latpublic static int lineStartsWithIgnoreCase(java.lang.Object[] ar, java.lang.String s, int startAt)
ar
- the array of objects, e.g., including LATITUDEs
- the String to be found, e.g., LatstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static int whichPrefix(java.lang.String[] prefixes, java.lang.String longerString, int startAt)
prefixes
- the array of prefixeslongerString
- the String that might start with one of the prefixesstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static java.lang.String findPrefix(java.lang.String[] prefixes, java.lang.String longerString, int startAt)
prefixes
- the array of prefixeslongerString
- the String that might start with one of the prefixesstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static int whichSuffix(java.lang.String[] suffixes, java.lang.String longerString, int startAt)
suffixes
- the array of suffixeslongerString
- the String that might end with one of the suffixesstartAt
- the first element of ar to be checked.
If startAt < 0, this starts with startAt = 0.public static java.lang.String[] split(java.lang.String s, char separator)
s
- a string with 0 or more separator chatactersseparator
- public static java.lang.String[] splitNoTrim(java.lang.String s, char separator)
s
- a string with 0 or more separator chatactersseparator
- public static int[] toIntArray(java.lang.Object[] oar)
oar
- an Object[]public static float[] toFloatArray(java.lang.Object[] oar)
oar
- an Object[]public static double[] toDoubleArray(java.lang.Object[] oar)
oar
- an Object[]public static int[] justFiniteValues(int[] iar)
iar
- is an int[]public static double[] justFiniteValues(double[] dar)
dar
- is a double[]public static java.lang.String[] removeNull(java.lang.String[] sar)
sar
- is a String[]public static java.lang.String[] removeNullOrEmpty(java.lang.String[] sar)
sar
- is a String[]public static int[] csvToIntArray(java.lang.String csv)
csv
- the comma-separated-value String.public static double[] csvToDoubleArray(java.lang.String csv)
csv
- the comma-separated-value Stringpublic static boolean parseBoolean(java.lang.String s)
s
- the stringpublic static byte parseBooleanToInt(java.lang.String s)
s
- the stringpublic static java.lang.String removeLeading(java.lang.String s, char ch)
s
- ch
- public static int parseInt(java.lang.String s, int def)
public static int parseInt(java.lang.String s)
s
- is the String representation of a number.public static double parseDouble(java.lang.String s)
s
- is the String representation of a number.public static boolean isDoubleTrouble(java.lang.String s)
This returns true if s is a value that causes Java to hang. Avoid java hang. 2011-02-09 http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308 This was Bob's work-around to avoid the Java bug.
s
- a string representing a double valuepublic static double roundingParseInt(java.lang.String s)
s
- is the String representation of a number.public static long parseLong(java.lang.String s)
s
- a valid String representation of a long valuepublic static float parseFloat(java.lang.String s)
s
- a String representing a float value (e.g., 1234.5 or 1234,5 or
1.234e3 1,234e3)public static java.lang.String[] tokenize(java.lang.String s)
s
- the space-separated stringpublic static java.lang.String noLongLines(java.lang.String s, int maxLength, java.lang.String spaces)
s
- a String with multiple lines, separated by \n'smaxLength
- the maximum line length allowedspaces
- the string to be inserted after the inserted newline, e.g., "<br> "
public static java.lang.String noLongLinesAtSpace(java.lang.String s, int maxLength, java.lang.String spaces)
s
- a String with multiple lines, separated by \n'smaxLength
- the maximum line length allowedspaces
- the string to be inserted after the inserted newline, e.g., " "public static java.lang.String genEFormat6(double d)
d
- a numberpublic static java.lang.String genEFormat10(double d)
d
- a numberpublic static java.lang.String genX10Format6(double d)
d
- a numberpublic static java.lang.String genX10Format10(double d)
d
- a numberpublic static java.lang.String genHTMLFormat6(double d)
d
- a numberpublic static java.lang.String genHTMLFormat10(double d)
d
- a numberpublic static java.lang.String trimStart(java.lang.String s)
s
- public static java.lang.String trimEnd(java.lang.String s)
s
- public static int binaryFindLastLE(java.lang.String[] sar, java.lang.String s)
sar
- an ascending sorted String[] which may have duplicate valuess
- public static int binaryFindFirstGE(java.lang.String[] sar, java.lang.String s)
sar
- an ascending sorted String[] which currently may not have duplicate values
s
- public static int binaryFindClosest(java.lang.String[] sar, java.lang.String s)
sar
- an ascending sorted String[].
It the array has duplicates and s equals one of them,
it isn't specified which duplicate's index will be returned.s
- public static int findInvalidUnicode(java.lang.String s, java.lang.String alsoOK)
s
- alsoOK
- a string with characters (e.g., \r, \n, \t) which are also validpublic static java.lang.String makeValidUnicode(java.lang.String s, java.lang.String alsoOK)
s
- alsoOK
- a string with characters (e.g., \r, \n, \t) which are also validpublic static char toIso88591Char(char ch)
ch
- the char to be convertedpublic static char[] toIso88591Chars(char[] car)
car[]
- the char[] to be convertedpublic static byte[] stringToUtf8Bytes(java.lang.String s)
public static java.lang.String utf8BytesToString(byte[] bar)
public static java.lang.String md5Hex(java.lang.String password)
password
- the text to be digestedpublic static java.lang.String passwordDigest(java.lang.String algorithm, java.lang.String password)
algorithm
- one of the FILE_DIGEST_OPTIONS
{"MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512" };password
- the text to be digestedpublic static java.lang.String md5Hex12(java.lang.String password)
public static java.lang.String differentLine(java.lang.String oldS, java.lang.String newS)
oldS
- newS
- public static int[] toRational(double d)
d
- public static java.lang.String encodeFileNameSafe(java.lang.String s)
THIS WON'T BE CHANGED. FILE NAMES CREATED FOR EDDGridCopy and EDDTableCopy DEPEND ON SAME ENCODING OVER TIME.
s
- public static java.lang.String encodeMatlabNameSafe(java.lang.String s)
THIS WON'T BE CHANGED. FILE NAMES CREATED FOR EDDGridFromFile and EDDTableFromFile DEPEND ON SAME ENCODING OVER TIME.
s
- public static java.lang.String simpleMatlabNameSafe(java.lang.String s)
THIS WON'T BE CHANGED. SOME datasetIDs DEPEND ON SAME ENCODING OVER TIME.
s
- public static java.lang.String quoteParameterIfNeeded(java.lang.String s)
public static java.lang.String toTitleCase(java.lang.String s)
public static java.lang.String toSentenceCase(java.lang.String s)
public static java.lang.String toVariableName(java.lang.String s)
s
- the starting string for the variable name.public static java.lang.String camelCaseToTitleCase(java.lang.String s)
s
- the camel case string.public static boolean isIso8859(java.lang.String s)
public static boolean isSomething(java.lang.String s)
public static boolean isSomething2(java.lang.String s)
public static java.lang.String periodSpaceConcat(java.lang.String a, java.lang.String b)
public static java.lang.String ifSomethingConcat(java.lang.String a, java.lang.String separator, java.lang.String b)
a
- may be null or "" or somethingseparator
- will only be used if a and b are something.b
- may be null or "" or something