Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





Java - Code Samples

 Sample 1. Code Sample / Example / Snippet of java.text.StringCharacterIterator

    public static String encode(String source) {

if (source == null) {

return "$e";

}

StringBuffer result = new StringBuffer();

StringCharacterIterator sci = new StringCharacterIterator(source);

for (char c = sci.current(); c != CharacterIterator.DONE; c = sci.next()) {

if (c == '$') {

result.append("$$");

}

else if (c == ',') {

result.append("$k");

}

else if (c == ' ') {

result.append("$n");

}

else if (c == ' ') {

result.append("$r");

}

else {

result.append(c);

}

}

return result.toString();

}


   Like      Feedback      java.text.StringCharacterIterator



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner