954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to replace repeated substring in other string?

Hi

I want to replace "ta,at,an,bc" in main string {ta,at,an,bc,ta,at,an,bc,ta,at,an,bc,ef,ta,at,an,bc,ta,at,an,bc" with (ta at an bc)*.The result array should be "(ta at an bc)*,e,(ta at an bc)*". Can anyone give me some hint? Thanks in advance.

perlsu
Newbie Poster
17 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

Look at the java.lang.String class' Java API doc through google. You should find what you're looking for.

Regards,

Nate

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

Have a counter variable that keeps track of the current index, iterate and find some new junk.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

You can use the String classes replaceAll method. Here is an example:

String str = "Hello blank";
String newStr = str.replaceAll("blank", "Jim") ;

System.out.println(newStr); //prints "Hello Jim"

For more help, www.NeedProgrammingHelp.com

NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You