This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Replace  RSS feed

 
Pankaj Shet
Ranch Hand
Posts: 312
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
Boost this thread!