public final class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
NEWLINE_CHARACTER
The line separator character (new line) for this platform (OS).
|
static String |
PATH_SEPARATOR
Deprecated.
use
File.separator |
| Modifier and Type | Method and Description |
|---|---|
static String |
addQuotations(String s) |
static int |
depthBelowCurrentPath(String basePath,
String comparePath,
String separator)
Compares two paths (case-insensitive), and returns whether one path is a subdirectory or not, and if so,
what depth this subdirectory is at.
|
static String |
getFullURLString(String protocol,
String domain,
int port,
String path)
Takes all the component parts needed to generate a valid URL, and returns the valid URL.
|
static boolean |
isEmpty(String str)
Deprecated.
|
static boolean |
isNotEmpty(String... strings)
Deprecated.
|
static String |
joinHostStringAndPath(String hostString,
String path)
Joins the host part of a URL to a path part of a URL, ensuring that we don't have too many slashes.
|
static String |
joinMetaPaths(String dataPath,
String metaPath,
String urlPath)
Joins three strings to make something which could be the file location of a URL path.
|
static String |
normalizeString(String string)
Normalizes the specified string by removing leading and trailing
whitespace characters.
|
static Long |
parseLong(String s) |
static String |
removeCharAt(String s,
int pos) |
static String |
removeQuotations(String s) |
static String |
replace(String someString,
char matchChar,
String replacement)
Replaces all occurrences of a character in a string and replaces them with a different string.
|
static String |
replace(String someString,
String matchString,
String replacement)
Replaces all occurrences of a particular substring in a string and replaces them with a different string.
|
static String |
safeSubstring(String source,
int beginIndex) |
static String |
safeSubstring(String source,
int beginIndex,
int endIndex) |
static Set<String> |
splitString(String input,
String delimiter)
Helper method to transform single string which contains multiple strings
delimited with delimiter into set of strings.
|
static boolean |
stringArrayContains(String[] array,
String contains,
boolean caseSensitive) |
static boolean |
stringEquals(String str1,
String str2) |
static boolean |
stringEqualsIgnoreCase(String str1,
String str2) |
static String |
trimIfNotNull(String string) |
public static final String PATH_SEPARATOR
File.separatorpublic static final String NEWLINE_CHARACTER
public static int depthBelowCurrentPath(String basePath, String comparePath, String separator)
depthBelowCurrentPath("/root/", "/root/SG1/", "/") will return 1
("/root/SG1/" is 1 directory below "/root/")
For example, depthBelowCurrentPath("/root/SG1/", "/root/", "/") will return -1
("/root/" is not below directory "/root/SG1/")
Also, depthBelowCurrentPath("/root/", "/root/", "/") will return 0 ("/root/"
the same as "/root/")
And depthBelowCurrentPath("/root/", "/toor/", "/") will return -1 (the directories are not
the same)basePath - The path you want to comparecomparePath - The path you want to compare againstseparator - The path separator. Normally, this will be "/"public static String replace(String someString, String matchString, String replacement)
someString - The String to replace the occurrences in.matchString - The substring you want to replace.replacement - The String you want to replace the matchChar character with.public static String replace(String someString, char matchChar, String replacement)
someString - The String to replace the occurrences in.matchChar - The character you want to replace.replacement - The String you want to replace the matchChar character with.public static String joinHostStringAndPath(String hostString, String path)
hostString - The host part of a URL, e.g. http://www.thiswebsite.com:8080path - The path part of a URL, e.g. /firstpath/public static String getFullURLString(String protocol, String domain, int port, String path)
String hostString = StringUtils.getFullURLString("http", "www.mywebsite.com", 8080, "/pages")
returns http://www.website.com:8080/pages.protocol - The protocol to use. If no protocol is supplied, "http" is presumed.domain - The domain to use, may be null.port - The port to use. If port is 80 and protocol is "http", port is not included in the URL.path - The path to use, may be null.null if both domain and path are null.public static String joinMetaPaths(String dataPath, String metaPath, String urlPath)
dataPath - Location where metadata is storedmetaPath - Metadata string you want to inserturlPath - URL of item you want to appendpublic static String normalizeString(String string)
null is replaced with an
empty string.string - the string to normalize; may be null.@Deprecated public static boolean isEmpty(String str)
@Deprecated public static boolean isNotEmpty(String... strings)
public static boolean stringArrayContains(String[] array, String contains, boolean caseSensitive)
public static String safeSubstring(String source, int beginIndex) throws ParseException
ParseExceptionpublic static String safeSubstring(String source, int beginIndex, int endIndex) throws ParseException
ParseExceptionpublic static Set<String> splitString(String input, String delimiter)
input - The String which contains multiple string valuesdelimiter - The delimiter used to split the stringsSet of stringsCopyright (c) 2014-2021 All Rights Reserved by the RWS Group for and on behalf of its affiliates and subsidiaries