• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Replace

 
Ranch Hand
Posts: 338
Scala Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic