import java.io.*;
import java.lang.*;
import java.util.*;
class stringtest{
public static void main(String args[])
{
StringBuffer str1=new StringBuffer("Roses are red and beautiful");
String str2 = "are";
System.out.println("String before removal \n "+str1);
int r,r1;
r=str1.indexOf(str2);
r1=str2.length();
if (r != -1) {
str1.delete(r,r1+r);
} else{
System.out.println("Sub string not found");
}
System.out.println("String after removal "+str1);
}
}
SAMPLE OUTPUT:
import java.lang.*;
import java.util.*;
class stringtest{
public static void main(String args[])
{
StringBuffer str1=new StringBuffer("Roses are red and beautiful");
String str2 = "are";
System.out.println("String before removal \n "+str1);
int r,r1;
r=str1.indexOf(str2);
r1=str2.length();
if (r != -1) {
str1.delete(r,r1+r);
} else{
System.out.println("Sub string not found");
}
System.out.println("String after removal "+str1);
}
}
SAMPLE OUTPUT:
No comments:
Post a Comment