Click to See Complete Forum and Search --> : substring replace
Randy_Bartels
Aug 18th, 2001, 07:25 PM
i need to use a method with similar functionality to PHP's substr_replace.
example:
example=substr_replace("this is a test","joke",10,4);
example contains "this is a joke";
example2:
example2=substr_replace("this is a test","joke",10,0);
example2 contains "this is a joketest";
filburt1
Aug 18th, 2001, 08:17 PM
Look in the JDK documentation for the String class.
Dillinger4
Aug 19th, 2001, 01:39 PM
You would probably want to use a StringBuffer instead.
The replace method of the String class is public String(char oldchar, char newchar) and the replace mathod of the StringBuffer class is public StringBuffer(int start, int end, String str)
public class Test{
public static void main(String[] args){
StringBuffer greeting = new StringBuffer("This is a test");
StringBuffer example2 = greeting.replace(10,14,"joke");
System.out.println(example2);
}
}
This is a joke.........
you can also insert by using the StringBuffer insert method:
There are too many to list but the one most used is public StringBuffer insert (int offset, String str);
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.