Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing whitespace in Java string?

I'm writing a parser for some LISP files. I'm trying to get rid of leading whitespace in a string. The string contents are along the lines of:

         :FUNCTION (LAMBDA
                   (DELTA
                    PLASMA-IN-0)
                 (IF
                  (OR
                   (>=
                    #61=(+
                         (*
                          1
                          DELTA)
                         PLASMA-IN-0)
                    100)
                   (<=
                    #61#
                    0))
                  PLASMA-IN-0
                  #61#))

The tabs are all printed as 4 spaces in the file, so I want to get rid of these leading tabs.

I tried to do this: string.replaceAll("\\s{4}", " ") - but it had no effect at all on the string.

Does anyone know what I'm doing wrong? Is it because it is a multi-line string?

Thanks

like image 716
bcoughlan Avatar asked Jan 23 '23 12:01

bcoughlan


1 Answers

String.trim();

Should work.

like image 148
dominic Avatar answered Jan 25 '23 03:01

dominic