Q:

Split string and delete every second space in java

I have log data in a raw file. It looks like this:
"2 A U W 2 0 1 1 1 1 1 6 0 0 1 0 0 0        U S E R N 1      F T Y 0 0 0 0 0 0 D 9         2 A I L 2 0 1 1 1 1 1 6" 

and so on.
I need to substring this string on messages of equal length (From "2 A U W" to "4 A I L" 400 bytes). This is made by String as = s.substring(0,400).toLowerCase(). But this is not enough for me. I want to make a message like this:
2auw 
20011111600100 
usern1 
fty000000d9

Can anyone help with it?

A:

You can add a back slash n "\n" to add line breaks to your string.
I'm not sure if this is the best way, but it is one way to do it:
If you know where you need the line breaks you can substring and add the back slash n. Something like this:
String s = as.substring(0,4) + "\n" + as.substring(4,18) + "\n" + //....and so on

Hope it helps

