1875 |
|
|
1876 |
return value; |
return value; |
1877 |
} |
} |
1878 |
|
|
1879 |
|
/** |
1880 |
|
* Returns true iff this String contains the sequence of Characters |
1881 |
|
* described in s. |
1882 |
|
* @param s the CharSequence |
1883 |
|
* @return true iff this String contains s |
1884 |
|
*/ |
1885 |
|
public boolean contains (CharSequence s) |
1886 |
|
{ |
1887 |
|
return this.indexOf(s.toString()) != -1; |
1888 |
|
} |
1889 |
|
|
1890 |
|
/** |
1891 |
|
* Returns a string that is this string with all instances of the sequence |
1892 |
|
* represented by <code>target</code> replaced by the sequence in |
1893 |
|
* <code>replacement</code>. |
1894 |
|
* @param target the sequence to be replaced |
1895 |
|
* @param replacement the sequence used as the replacement |
1896 |
|
* @return the string constructed as above |
1897 |
|
*/ |
1898 |
|
public String replace (CharSequence target, CharSequence replacement) |
1899 |
|
{ |
1900 |
|
String targetString = target.toString(); |
1901 |
|
String replaceString = replacement.toString(); |
1902 |
|
int targetLength = target.length(); |
1903 |
|
int replaceLength = replacement.length(); |
1904 |
|
|
1905 |
|
int startPos = this.indexOf(targetString); |
1906 |
|
StringBuilder result = new StringBuilder(this); |
1907 |
|
while (startPos != -1) |
1908 |
|
{ |
1909 |
|
// Replace the target with the replacement |
1910 |
|
result.replace(startPos, startPos + targetLength, replaceString); |
1911 |
|
|
1912 |
|
// Search for a new occurrence of the target |
1913 |
|
startPos = result.indexOf(targetString, startPos + replaceLength); |
1914 |
|
} |
1915 |
|
return result.toString(); |
1916 |
|
} |
1917 |
} |
} |