Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Replace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Replace" Watch "String Replace" New topic

String Replace

Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 289

Hi friends,
I am developing a program which reads all lines from the files, and replace each , by | except for every String in a line.

i.e. if there is a line "My","Name is, Pankaj",0,1,1,1, "Abc xyzr, mum."

I want to replace each , except for those which lie between "".
i.e. the output should be,

"My"|"Name is, Pankaj"|0|1|1|1|"Abc xyzr, mum."

What I did is

I am getting is:
"My"|"Name is, Pankaj",0,1,1,1,"Abc xyzr, mum."

How to proceed further?
Please help me solve this problem.

Help is always appreciated.

[Edit - UseCodeTags - MB]

B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Sebanti Sanyal
Ranch Hand

Joined: Nov 07, 2011
Posts: 58

If ',' occurs after even no. of double quotes,that means it is not enclosed by a string and should be replaced. My solution:

It is not really optimized because of the for loop. Is there a short-cut?
I agree. Here's the link:
subject: String Replace
It's not a secret anymore!