Package ucar.nc2.ogc.erddap.util
Class ErddapString2
- java.lang.Object
-
- ucar.nc2.ogc.erddap.util.ErddapString2
-
public class ErddapString2 extends Object
A class with static String methods that add to native String methods. All are static methods.
-
-
Constructor Summary
Constructors Constructor Description ErddapString2()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
indexOf(char[] cArray, char c, int fromIndex)
Finds the first instance of c at or after fromIndex (0..static boolean
isDigit(int c)
0..9.static boolean
isLetter(int c)
This includes hiASCII/ISO Latin 1/ISO 8859-1, but not extensive unicode characters.static double
parseDouble(String s)
Convert a string to a double.static int
parseInt(String s)
Convert a string to an int.static long
parseLong(String s)
This converts String representation of a long.static String
replaceAll(String s, char oldCh, char newCh)
Returns a string where all occurences of oldCh have been replaced with newCh.static int[]
toRational(double d)
This converts a double to a rational number (m * 10^t).
-
-
-
Field Detail
-
ERROR
public static String ERROR
ERROR is a constant so that it will be consistent, so that one can search for it in output files. This is NOT final, so EDStatic can change it. This is the original definition, referenced by many other classes.
-
-
Method Detail
-
indexOf
public static int indexOf(char[] cArray, char c, int fromIndex)
Finds the first instance of c at or after fromIndex (0.. ) in cArray.- Parameters:
cArray
-c
- the char you want to findfromIndex
- the index number of the position to start the search- Returns:
- The first instance of c. If not found, it returns -1.
-
isLetter
public static boolean isLetter(int c)
This includes hiASCII/ISO Latin 1/ISO 8859-1, but not extensive unicode characters. Letters are A..Z, a..z, and #192..#255 (except #215 and #247). For unicode characters, see Java Lang Spec pg 14.- Parameters:
c
- a char- Returns:
- true if c is a letter
-
isDigit
public static boolean isDigit(int c)
0..9. Non-Latin numeric characters are not included (see Java Lang Spec pg 14).- Parameters:
c
- a char- Returns:
- true if c is a digit
-
replaceAll
public static String replaceAll(String s, char oldCh, char newCh)
Returns a string where all occurences of oldCh have been replaced with newCh. This doesn't throw exceptions if bad values.
-
parseInt
public static int parseInt(String s)
Convert a string to an int. Leading or trailing spaces are automatically removed. This accepts hexadecimal integers starting with "0x". Leading 0's (e.g., 0012) are ignored; number is treated as decimal (not octal as Java would). Floating point numbers are rounded. This won't throw an exception if the number isn't formatted right. To make a string from an int, use ""+i, Integer.toHexString, or Integer.toString(i,radix).- Parameters:
s
- is the String representation of a number.- Returns:
- the int value from the String (or Integer.MAX_VALUE if error).
-
parseDouble
public static double parseDouble(String s)
Convert a string to a double. Leading or trailing spaces are automatically removed. This accepts hexadecimal integers starting with "0x". Whole number starting with '0' (e.g., 012) is treated as decimal (not octal as Java would). This won't throw an exception if the number isn't formatted right.- Parameters:
s
- is the String representation of a number.- Returns:
- the double value from the String (a finite value, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, or Double.NaN if error).
-
parseLong
public static long parseLong(String s)
This converts String representation of a long. Leading or trailing spaces are automatically removed. This *doesn't* round. So floating point values lead to Long.MAX_VALUE.- Parameters:
s
- a valid String representation of a long value- Returns:
- a long (or Long.MAX_VALUE if trouble).
-
toRational
public static int[] toRational(double d)
This converts a double to a rational number (m * 10^t). This is similar to Math2.mantissa and Math2.intExponent, but works via string manipulation to avoid roundoff problems (e.g., with 6.6260755e-24).- Parameters:
d
-- Returns:
- int[2]: [0]=m, [1]=t. (or {0, 0} if d=0, or {1, Integer.MAX_VALUE} if !finite(d))
-
-