Home  | My Account  |  Membership
WorldDeveloper.org
Forum Details
Topics
Posts
Categories
 
577 member(s)
718,905 hit(s)
14 categories
51 topics
26 messages
0 online
Forums: J2ME Development
J2ME: replaceAll for Strings
hostj2me
43 topic(s)
23 post(s)

May 28, 2007 8:25 PM


public static String replaceAll(String text, String old, String newString)
{
int next = text.indexOf(old);
if ( next == -1 )
{
return text;
}
else
{
StringBuffer buffer = new StringBuffer(text.substring(0,next));
buffer.append(newString);
int current = next+old.length(), stop = text.length();
for ( ; current stop && (next = text.indexOf(old,current)) != -1; )
{
buffer.append(text.substring(current, next));
buffer.append(newString);
current = next+old.length();
}

if ( current stop )
{
buffer.append(text.substring(current));
}

return buffer.toString();
}
}


©2008 WorldDeveloper.org - PO Box 310575 Miami, FL 33231

WorldDeveloper.org is a managed social network for application developers around the world.