Rahul
Posts: 52
Nickname: wildhorse
Registered: Oct, 2002
|
|
Re: HELP simple problem with chars
|
Posted: May 29, 2003 11:12 PM
|
|
To remove an s from the string, use indexOf(int ch) method of String class:
Here's a method that removes all s's from a string:
String s = "susie says its easy";
for (int i=0; i< s.length() ;i++ )
{
if (i==s.indexOf('s')){
if (i==0)
s = s.substring(i+1,s.length());
else
s = s.substring(0,i) + s.substring(i+1,s.length());
}
}
This makes it generic.
You may put a 'break;' after the first 'if' is encountered. It ensures that only the first s is removed. You can of course customize the code above to your needs.
|
|