cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Remove the character "\n" and empty spaces from string

nchrk
New Contributor II

i trying to remove the โ€œ\nโ€ character along with empty spaces from string thru mapper expression, but itโ€™s not working.

  1. input value JsonStr := [\n โ€œACโ€\n]
    expected output := [โ€œACโ€]
  2. input value JsonStr := [\n โ€œACโ€,\n โ€œBDโ€,\n โ€œDEโ€ \n]
    expected output := [โ€œACโ€,โ€œBDโ€,โ€œDEโ€]
    i tried with JsonStr.toString().replaceAll(/\n/,โ€œโ€). but itโ€™s not working
1 ACCEPTED SOLUTION

You can use this expression: $JsonStr != null && $JsonStr != โ€œโ€ ? $JsonStr .replaceAll(โ€œ\nโ€,โ€œโ€) : $JsonStr

Explanation: This will first check if the JsonStr is null or empty, if itโ€™s not then itโ€™ll do the replacing else itโ€™ll just put input jsonStr as output. In your case where JsonStr is null itโ€™ll show output null

image

View solution in original post

7 REPLIES 7

nchrk
New Contributor II

i changed expression as below, itโ€™s working
JsonStr.toString().replaceAll(โ€˜\nโ€™,โ€˜โ€™).replaceAll(โ€™ โ€˜,โ€™')

nchrk
New Contributor II

expression failing when input string contains blanks or null values using this expression โ€œJsonStr.toString().replaceAll(โ€˜\nโ€™,โ€˜โ€™).replaceAll(โ€™ โ€˜,โ€™')โ€

any suggestions how to resolve this when we receive blank/null values?

Can you share example of input data(with blank/ null values)

  1. input value JsonStr := [\n โ€œACโ€\n]
    expected output := [โ€œACโ€]
  2. input value JsonStr := [\n โ€œACโ€,\n โ€œBDโ€,\n โ€œDEโ€ \n]
    expected output := [โ€œACโ€,โ€œBDโ€,โ€œDEโ€]
  3. input value JsonStr := null
    expected output := null