Replacing Characters in a String
// Replace all occurrences of 'a' with 'o'String newString = string.replace('a', 'o');Replacing Substrings in a Stringstatic String replace(String str,String pattern, String replace) {int s = 0;int e = 0;StringBuffer result = new StringBuffer();while ((e = str.indexOf(pattern, s)) >= 0) {result.append(str.substring(s, e));result.append(replace);s = e+pattern.length();}result.append(str.substring(s));return result.toString();}Converting a String to Upper or Lower Case// Convert to upper caseString upper = string.toUpperCase();// Convert to lower caseString lower = string.toLowerCase();Converting a String to a Numberint i = Integer.parseInt("123");long l = Long.parseLong("123");float f = Float.parseFloat("123.4");double d = Double.parseDouble("123.4e10");Breaking a String into WordsString aString = "word1 word2 word3";StringTokenizer parser =new StringTokenizer(aString);while (parser.hasMoreTokens()) {processWord(parser.nextToken());
-
Interview Candidate
- Aug 28th, 2004
- 0
- 1934
This Question is not yet answered!
Related Answered Questions
Related Open Questions
Replacing Characters in a String
This Question is not yet answered!
Related Answered Questions
Related Open Questions