How to remove character in a String list?
1 posts in topic
Flat View  Flat View

Posted By:   stanley_ten
Posted On:   Thursday, June 7, 2001 07:38 PM

I have a String "ABCDJJLMN" ,
how can i remove the both "J" character ?

Re: How to remove character in a String list?

Posted By:   Michael_Wax  
Posted On:   Friday, June 8, 2001 08:03 AM

The answer depends on what exactly you are trying to do. If you are looking for a method that will remove a substring from a given string, the following will work, but it is not necessarily optimal for repeated use.

public String removeSubstring(String string, String substring) {
int start = string.indexOf(substring);
//don't change anything if the substring is not present
if (start > -1)
string = string.substring(0,start) + string.substring(start+substring.length());
return string;
About | Sitemap | Contact