I have copied and pasted some output from a .log file into a mathematica notebook however the resulting output in the notebook contains many whitespaces between lines.

Is there a way to eliminate all whitespaces between characters in the string? I've tried StringReplace/ StringDelete in built routines but as a black box routine only accounts for a user defined number of whitespaces to remove rather than an arbitrary number (this number fluctuating from line to line in my rather long string output).

To be precise, I have something like string1\n\n\n\n\n\nstring2\n\n\nstring3 where \n means a whitespace and the number of whitespaces in principle changes between differing strings. I'd like to write this as string1string2string3

If it's important stringi are combinations of letters,^,*,+,- and [], e.g. string1 = [1/a]^-1*b etc..


1 Answer 1

s = "string1\n\n\n\n\n\nstring2\n\n\nstring3";
StringDelete[s, WhitespaceCharacter]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.