|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.ttools.func.Strings
public class Strings
String manipulation and query functions.
Method Summary | |
---|---|
static String |
concat(String s1,
String s2)
Concatenates two strings. |
static String |
concat(String s1,
String s2,
String s3)
Concatenates three strings. |
static String |
concat(String s1,
String s2,
String s3,
String s4)
Concatenates four strings. |
static boolean |
contains(String whole,
String sub)
Determines whether a string contains a given substring. |
static boolean |
endsWith(String whole,
String end)
Determines whether a string ends with a certain substring. |
static boolean |
equals(String s1,
String s2)
Determines whether two strings are equal. |
static boolean |
equalsIgnoreCase(String s1,
String s2)
Determines whether two strings are equal apart from possible upper/lower case distinctions. |
static int |
length(String str)
Returns the length of a string in characters. |
static boolean |
matches(String str,
String regex)
Tests whether a string matches a given regular expression. |
static String |
matchGroup(String str,
String regex)
Returns the first grouped expression matched in a string defined by a regular expression. |
static String |
padWithZeros(long value,
int ndigit)
Takes an integer argument and returns a string representing the same numeric value but padded with leading zeros to a specified length. |
static String |
replaceAll(String str,
String regex,
String replacement)
Replaces all occurrences of a regular expression in a string with a different substring value. |
static String |
replaceFirst(String str,
String regex,
String replacement)
Replaces the first occurrence of a regular expression in a string with a different substring value. |
static boolean |
startsWith(String whole,
String start)
Determines whether a string starts with a certain substring. |
static String |
substring(String str,
int startIndex)
Returns the last part of a given string. |
static String |
substring(String str,
int startIndex,
int endIndex)
Returns a substring of a given string. |
static String |
toLowerCase(String str)
Returns an uppercased version of a string. |
static String |
toUpperCase(String str)
Returns an uppercased version of a string. |
static String |
trim(String str)
Trims whitespace from both ends of a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String concat(String s1, String s2)
s1+s2
, but blank values can sometimes appear as
the string "null
" if you do it like that.
s1
- first strings2
- second string
s1
followed by s2
concat("blue", "moon") = "bluemoon"
public static String concat(String s1, String s2, String s3)
s1+s2+s3
, but blank values can sometimes appear as
the string "null
" if you do it like that.
s1
- first strings2
- second strings3
- third string
s1
followed by s2
followed by s3
concat("a", "b", "c") = "abc"
public static String concat(String s1, String s2, String s3, String s4)
s1+s2+s3+s4
,
but blank values can sometimes appear as
the string "null
" if you do it like that.
s1
- first strings2
- second strings3
- third strings4
- fourth string
s1
followed by s2
followed by s3
followed by s4
concat("a", "b", "c", "d") = "abcd"
public static boolean equals(String s1, String s2)
s1==s2
,
which can (for technical reasons) return false even if the
strings are the same.
s1
- first strings2
- second string
public static boolean equalsIgnoreCase(String s1, String s2)
s1
- first strings2
- second string
equalsIgnoreCase("Cygnus", "CYGNUS") = true
, equalsIgnoreCase("Cygnus", "Andromeda") = false
public static boolean startsWith(String whole, String start)
whole
- the string to teststart
- the sequence that may appear at the start of
whole
whole
are
the same as start
startsWith("CYGNUS X-1", "CYG") = true
public static boolean endsWith(String whole, String end)
whole
- the string to testend
- the sequence that may appear at the end of
whole
whole
are
the same as end
endsWith("M32", "32") = true
public static boolean contains(String whole, String sub)
whole
- the string to testsub
- the sequence that may appear within whole
sub
appears within
whole
contains("Vizier", "izi") = true
public static int length(String str)
str
- string
str
length("M34") = 3
public static boolean matches(String str, String regex)
str
- string to testregex
- regular expression string
regex
matches str
anywherematches("Hubble", "ub") = true
public static String matchGroup(String str, String regex)
str
- string to match againstregex
- regular expression containing a grouped section
regex
didn't match str
)matchGroup("NGC28948b","NGC([0-9]*)") = "28948"
public static String replaceFirst(String str, String regex, String replacement)
str
- string to manipulateregex
- regular expression to match in str
replacement
- replacement string
str
, but with the first match (if any) of
regex
replaced by replacement
replaceFirst("Messier 61", "Messier ", "M-") = "M-61"
public static String replaceAll(String str, String regex, String replacement)
str
- string to manipulateregex
- regular expression to match in str
replacement
- replacement string
str
, but with all matches of
regex
replaced by replacement
replaceAll("1-2--3---4","--*","x") = "1x2x3x4"
public static String substring(String str, int startIndex)
str
- the input stringstartIndex
- the beginning index, inclusive
str
, omitting the first
startIndex
characterssubstring("Galaxy", 2) = "laxy"
public static String substring(String str, int startIndex, int endIndex)
startIndex
and continues to the character at index endIndex-1
Thus the length of the substring is endIndex-startIndex
.
str
- the input stringstartIndex
- the beginning index, inclusiveendIndex
- the end index, inclusive
str
substring("Galaxy", 2, 5) = "lax"
public static String toUpperCase(String str)
str
- input string
str
toUpperCase("Universe") = "UNIVERSE"
public static String toLowerCase(String str)
str
- input string
str
toLowerCase("Universe") = "universe"
public static String trim(String str)
str
- input string
trim(" some text ") = "some text"
, trim("some text") = "some text"
public static String padWithZeros(long value, int ndigit)
value
- numeric value to padndigit
- the number of digits in the resulting string
value
with
at least ndigit
characterspadWithZeros(23,5) = "00023"
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |