All this regex stuff has me really confused. How could I just replace all the occurrences of "\\" in a string with "\n"?

Recommended Answers

All 4 Replies

String newString = oldString.replace("\\","\n");
String newString = oldString.replace("\\","\n");

That kind of works. The problem with it though is that it also replaces instances of "\" with a "\n". I only want instances of "\\" to be replaced with a "\n".

Well, use "\\\\" then.

It works! Excellent! Thank you so much! Solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.