Wednesday, November 21, 2012

SUBSTRING REMOVAL USING STRING BUFFER CLASS


/* SUBSTRING REMOVAL USING STRING BUFFER CLASS */

class stri
{
public static void main(String args[])
{
StringBuffer str=new StringBuffer("welcome to java program");
String substr ="to";
System.out.println("String before removal :"+str);
System.out.println("substring is:"+substr);
int l,l1;
l=str.indexOf(substr);
l1=substr.length();
if(l!=-1)
{
str=str.delete(l,l+ l1);
}
else
{
System.out.println("substring not found");
}
System.out.println("After substring removal:" +str);
}
}

Output:

0 comments:

Post a Comment