-1

I have a request payload that I need comes with new lines '\n' that I'm removing using the regex below:

replaceAll("\n", "")

However it then leaves such a string:

eK7jVPstMFlOJ\/\/PtFIOKgSODxmjpQNgm9ASwQzP0v2RJbZzVXEB5ZOKVxiILhSCng25D87K8P9oHFScbS6OsmGDIf1HMDlXmcSn0JuBFfhx36GGoLpMq3\/xH3wB1Ku5x5\/6WSiijsYit28Rf\/3ZsK2U1PCc9NVVAeoZvLsn\/skjishzVGKJv9elOgkXcoM2F3LbMlrwjw9j4lx07RbeGfq9H7+oANeLCreSZEpe7iC8+zKatT4TCrb7Q3ZW\/FlE1\/JwnOphvdcKDoQvzPrxizN9idrwidF6\/y30CkCB+aW39Bb5dB+YdXmW9eZJNt4ZlI9embs+ZwAKNgZq\/52W\/Q=="

hence I get the error response:No content to map due to end-of-input\n at [Source: (String)\"\"; line: 1, column: 0]

How can I remove the new lines and the backslashes, only the forward slashes are to be retained

(The sample/final formatted code should look something like,with forward slashes only)

qRqWnruUJGoEGuBPcRRe4Td/BkesYk0KdoaNO6j7QQULZExKE8jVnFdzjJxNA2GPkazen/hcKx3+DMQ7RWupau473z6uF0iVjxcl/U6mTQbtY5tb8c/Qq64C5nYU+iplW+/e1lWyKzZed7IegNRVSABKbyyTrqTmQCghPMCY3evo/YwF0EovKw5Zw1U1BzjMizr7jhBihTsq71WE4MXW4iyhxGbnvPuzqpXBowjcOAyx433PjRDZnty5mum3TeETJMpoF20ULa7q5mnNCW6JbkZErhzGbY5thJNeYUvwhlsP3qFYNlFkO0kKax/nEfxFC6muowOOrFsqerbP0lcAHQ==
Boron
  • 99
  • 10
  • 34

1 Answers1

-1

Sounds like all you need to do is replace your backslashes too...

You can chain calls, so try something like this:

final String result = original.replaceAll("\n", "")
                              .replaceAll("\\\\", "");

Or, for a single line solution:

final String result = original.replaceAll("([\\\\\n])", "");
Daniel Scarfe
  • 199
  • 1
  • 8
  • With the first solution, I am still getting something like this `\/` and with the second solution, all the back slashes and forward slashes are replaced – Boron Jul 29 '19 at 10:26
  • @Boron No, that code can't remove forward slashes. You are doing something wrong. – Wiktor Stribiżew Jul 29 '19 at 12:17