Replaces all of the instances of the find String with newStr in the (first) given String. @param original The input String in which the String replacement should take place @param find The String to find within the input String, and which will be replaced
(String original, String find, String replace)
| 147 | * replacement String |
| 148 | */ |
| 149 | public static String replaceAll(String original, String find, String replace) |
| 150 | { |
| 151 | int startindex = original.indexOf(find); |
| 152 | |
| 153 | if (startindex < 0) |
| 154 | { |
| 155 | return original; |
| 156 | } |
| 157 | |
| 158 | char[] working = original.toCharArray(); |
| 159 | StringBuilder sb = |
| 160 | new StringBuilder(original.length() + replace.length()); |
| 161 | |
| 162 | int currindex = 0; |
| 163 | |
| 164 | while (startindex > -1) |
| 165 | { |
| 166 | for (int i = currindex; i < startindex; ++i) |
| 167 | { |
| 168 | sb.append(working[i]); |
| 169 | } |
| 170 | |
| 171 | currindex = startindex; |
| 172 | sb.append(replace); |
| 173 | currindex += find.length(); |
| 174 | startindex = original.indexOf(find, currindex); |
| 175 | } |
| 176 | |
| 177 | for (int i = currindex; i < working.length; ++i) |
| 178 | { |
| 179 | sb.append(working[i]); |
| 180 | } |
| 181 | |
| 182 | return sb.toString(); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Tests to see if the given String has balanced parenthesis. Balanced means |