This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent: how to remove ^M (newline) characters using Java?

 
Annie Zhang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to remove ^M (newline) characters using Java? Could you please show me the snippet? I am using java version 1.3, so I couldn't use java.util.regex.

Thanks a lot,
Annie
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start with the "more typing" solution. There are shorter ones but this one will get you started. In this forum we often give broad hints and send you looking in the API for details ...


Look at the API docs for String to see if you can find "position of" and how to get the part of a string up to position i, the part of a string after position i. Take a shot at some code and let us see how it works.
 
Annie Zhang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan for your reply. I was confused by the "^M" in the unix text file. After I replaced it with "\r\n", everything works now.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps native2ascii is a program for you?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic