472,989 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

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 60371
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

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

Similar topics

1
by: gipsy boy | last post by:
// -- using namespace std; map<string,string> formMap; list<string> formParams; for(list<string>::iterator fit = formParams.begin(); fit!=formParams.end(); fit++) { cout << "key=" << *fit;...
3
by: soni29 | last post by:
hi, how can i remove a string from an existing string in javascript. i have a textbox in a form and want to make sure that when the user clicks a button that certain words are moved, like all...
7
by: herrcho | last post by:
i'm in the course of learning C, and found these two words "string, string literal" confusing me.. I'd like to know the difference between them.. Thank you
5
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
7
by: Wilson | last post by:
Hi, How do get the Dictioanry object from FiedlInfo ? my code : fieldInfo = this.GetType().GetField("dictioanry1"); ??Dictionary<string, string> dicTemp1 = (Dictionary<string,...
2
by: Steve Richter | last post by:
KeyValuePair<string,stringhas a ToString method that returns the KeyValue pair seperated by a comma and enclosed in : Is this method used as a building block for serialization? The reason I...
2
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: Contract StockContract = new Contract();...
1
by: Leigh Finch | last post by:
Hey Guys, Quick question about the PHP compiler, is there any performance difference between $string .= $new; and $string = $string . $new;
2
by: drjay1627 | last post by:
I need help with inserting a string for both key and value to a map. while(!myHuffFile.eof()){ string word, code; int freq; myHuffFile >> word >> freq >> code; if(word == ""){...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.