org.eclipse.gmf.runtime.common.core.util
Class StringUtil
java.lang.Object
org.eclipse.gmf.runtime.common.core.util.StringUtil
-
public class StringUtil
- extends java.lang.Object
In JDK 1.3 we don't have the luxury of replaceAll as in JDK 1.4.
The replace methods from this string class are intended to be used
until JDK 1.4 is used.
For completely different implementations of the replace methods, please see
https://forum.java.sun.com/thread.jsp?forum=31&thread=284142&message=1109785
Replacing a whole word is completely different from replacing all instances.
To avoid confusion, the method names are different too.
Method Summary
|
static boolean
|
doesWordExist
(java.lang.String string,
java.lang.String source,
boolean caseSensitive)
Returns if a substring was found as a whole word in a string. |
static java.lang.String
|
encodeURL
(java.lang.String url)
Encode the url string |
static boolean
|
isValidPositiveInteger
(java.lang.String string)
Do not use Integer.parseInt(). |
static java.lang.String
|
replace
(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
Replace the first instance of part of a string with another string. |
static java.lang.String
|
replaceAll
(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
Replace all instances of part of a string with another string |
static java.lang.String
|
replaceAllWholeWords
(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
Replaces whole words found in one string with another string. |
static java.lang.String
|
replaceWholeWords
(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
Replaces whole words found in one string with another string. |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
|
replace
public static java.lang.String replace(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
- Replace the first instance of part of a string with another string.
-
-
Parameters:
-
string
- is the string that contains the substring to be replaced -
source
- is the substring that will be replaced if it is found
in the string -
dest
- what the substring will be replaced with if it is found
in the string -
caseSensitive
- true to do a case sensitive search, false to do
a case insensitive search
-
Returns:
- the string containing the first instance of source replaced
with dest
replaceAll
public static java.lang.String replaceAll(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
- Replace all instances of part of a string with another string
-
-
Parameters:
-
string
- is the string that contains the substring to be replaced -
source
- is the substring that will be replaced if it is found
in the string -
dest
- what the substring will be replaced with if it is found
in the string -
caseSensitive
- true to do a case sensitive search, false to do
a case insensitive search
-
Returns:
- the string containing all instances of source replaced with dest
replaceWholeWords
public static java.lang.String replaceWholeWords(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
- Replaces whole words found in one string with another string.
The whole words are delimted by delimiters defined in the DELIMTERES
constant.
-
-
Parameters:
-
string
- is the string that contains the substring to be replaced -
source
- is the substring that will be replaced if it is found
in the string -
dest
- what the substring will be replaced with if it is found
in the string -
caseSensitive
- true to do a case sensitive search, false to do
a case insensitive search
-
Returns:
- the string containing the first instance of source replaced with
dest.
replaceAllWholeWords
public static java.lang.String replaceAllWholeWords(java.lang.String string,
java.lang.String source,
java.lang.String dest,
boolean caseSensitive)
- Replaces whole words found in one string with another string.
The whole words are delimted by delimiters defined in the DELIMTERES
constant.
-
-
Parameters:
-
string
- is the string that contains the substring to be replaced -
source
- is the substring that will be replaced if it is found
in the string -
dest
- what the substring will be replaced with if it is found
in the string -
caseSensitive
- true to do a case sensitive search, false to do
a case insensitive search
-
Returns:
- the string containing all instances of source replaced with
dest.
doesWordExist
public static boolean doesWordExist(java.lang.String string,
java.lang.String source,
boolean caseSensitive)
- Returns if a substring was found as a whole word in a string.
The whole words are delimted by delimiters defined in the DELIMTERES
constant.
-
-
Parameters:
-
string
- is the string that contains the substring to be replaced -
source
- is the substring that we are checking for in string -
caseSensitive
- true to do a case sensitive search, false to do
a case insensitive search
-
Returns:
- boolean true if the string was found as a word, false if the
string was not found as a word.
isValidPositiveInteger
public static boolean isValidPositiveInteger(java.lang.String string)
- Do not use Integer.parseInt(). This is doing something different.
Based on code from Gleb's SetMultiplicityDialog.
-
-
Parameters:
-
string
- to check if it is a valid positive integer
-
Returns:
- true if it's a valid positive integer, false if it isn't
encodeURL
public static java.lang.String encodeURL(java.lang.String url)
- Encode the url string
-
-
Parameters:
-
url
- String to encode
-
Returns:
- String encoded URL
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.