Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Replace

 
Pankaj Shet
Ranch Hand
Posts: 300
Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Sebanti Sanyal
Ranch Hand
Posts: 58
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic