469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Remove sub string from a string in JAVA.

37
Hi all,

Does anyone have suggestion what can I do to remove some string from a string?
Like this :

Original : I have a cat.
Remove : have
Result : I a cat.

Thanks in advance.
Aug 23 '07 #1
10 59917
r035198x
13,262 8TB
Hi all,

Does anyone have suggestion what can I do to remove some string from a string?
Like this :

Original : I have a cat.
Remove : have
Result : I a cat.

Thanks in advance.
The specs for the String class has the method you're looking for.
Aug 23 '07 #2
praveen2gupta
201 100+
Hi all,

Does anyone have suggestion what can I do to remove some string from a string?
Like this :

Original : I have a cat.
Remove : have
Result : I a cat.

Thanks in advance.
Hi
There is a String class and some methods are associated with it. Read this class and their methods , your problem will be solved
Aug 23 '07 #3
Nepomuk
3,112 Expert 2GB
There is a String class and some methods are associated with it. Read this class and their methods , your problem will be solved
The String class should solve the problem, providing you don't need anything exotic (like "delete all words that start with an 'h'"). But even then, you'll be able to use the given methods to solve the problem, it will be a bit more work though.
Aug 23 '07 #4
r035198x
13,262 8TB
The String class should solve the problem, providing you don't need anything exotic (like "delete all words that start with an 'h'"). But even then, you'll be able to use the given methods to solve the problem, it will be a bit more work though.
Regular expressions
Aug 23 '07 #5
Nepomuk
3,112 Expert 2GB
Regular expressions
Arg, didn't think of that. But at least I wasn't totally mistaken:
The package java.util.regex is only provided from java 1.4, some of it even from java 1.5 onwards, so for backwards compatibility... ^^ OK, hardly anyone uses something older than 1.5 these days, but you never know! :-D
Aug 23 '07 #6
gaya3
184 100+
Hi all,

Does anyone have suggestion what can I do to remove some string from a string?
Like this :

Original : I have a cat.
Remove : have
Result : I a cat.

Thanks in advance.

Hi,
following code will help u..

class Stringremoval
{
public static void main(String args[])
{
String sample="i have book";
StringBuffer s = new StringBuffer(sample);
StringBuffer AfterRemoval=s.delete(2,6);
System.out.println("removed part:"+removedpart);
}
}


-Thanks & Regards
Hamsa
Aug 23 '07 #7
JosAH
11,448 Expert 8TB
Hi,
following code will help u..

class Stringremoval
{
public static void main(String args[])
{
String sample="i have book";
StringBuffer s = new StringBuffer(sample);
StringBuffer AfterRemoval=s.delete(2,6);
System.out.println("removed part:"+removedpart);
}
}


-Thanks & Regards
Hamsa
Spoiler: removing part of a String is identical to replacing that part of the String
by nothing, i.e. the empty String "". There's no need for all those statements
(what is "removedpart"?)

kind regards,

Jos
Aug 23 '07 #8
teenIce
37
Hi,

I had found the code to replace sub string in string. The code can be like this :

Expand|Select|Wrap|Line Numbers
  1. String tmpString = myString.replace(textToReplace,"");  
Thanks all.. :)
Aug 24 '07 #9
gaya3
184 100+
Spoiler: removing part of a String is identical to replacing that part of the String
by nothing, i.e. the empty String "". There's no need for all those statements
(what is "removedpart"?)

kind regards,

Jos


hi,
sry its not "removedpart" in tat pgm... its "Afterremoval" which is string...
wat u said also rite..(removing --replacing the string with"")
Aug 24 '07 #10
r035198x
13,262 8TB
Hi,

I had found the code to replace sub string in string. The code can be like this :

Expand|Select|Wrap|Line Numbers
  1. String tmpString = myString.replace(textToReplace,"");  
Thanks all.. :)
Great work. You'll often find that those doc pages usually have what you need.
Aug 24 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by gipsy boy | last post: by
3 posts views Thread by soni29 | last post: by
1 post views Thread by Leigh Finch | last post: by
2 posts views Thread by drjay1627 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.