I have below string
String str="select * from m_menus;
select * from m_roles";
I want above string in one line like
String str="select * from m_menus;select * from m_roles";
I have tried
str1=str.replace("[\r\n]+", " ");
and also
str1=str.replace("\n"," ");
Both are not working.
Select the lines you want to join ( Ctrl + A to select all) Choose Edit -> Line Operations -> Join Lines.
Step 1: Be prepared with the text which you want to convert. Step 2: Copy the text, JSON, String, Pdf or XML (whichever you want to convert). Step 3: Paste the copied content in the space provided. Step 4: Finally click the "convert" option to get the text converted in a single line.
You can put multiple lines in a cell with pressing Alt + Enter keys simultaneously while entering texts. Pressing the Alt + Enter keys simultaneously helps you separate texts with different lines in one cell.
Raw StringsThey can span multiple lines without concatenation and they don't use escaped sequences. You can use backslashes or double quotes directly.
No regular expressions and operating system independent:
str1.replaceAll(System.lineSeparator(), " ");
Windows uses \r\n as a line breaker, while *nix systems use only \n.
Use String.replaceAll
instead.
str1=str.replaceAll("[\r\n]+", " ");
If you want to use regex, you should use the String.replaceAll()
method.
Why don't you use str.replaceAll("\r\n", " ")
?
Should work and replace all occurences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With