This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Replace" Watch "String Replace" New topic
Author

String Replace

Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 272

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.
Thanks,
-Pankaj.

[Edit - UseCodeTags - MB]


PANKAJ SHET
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?
 
jQuery in Action, 2nd edition
 
subject: String Replace