Forum Discussion

nchrk's avatar
nchrk
New Contributor II
3 years ago
Solved

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

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

7 Replies

  • nchrk's avatar
    nchrk
    New Contributor II

    i changed expression as below, it’s working
    JsonStr.toString().replaceAll(‘\n’,‘’).replaceAll(’ ‘,’')

  • nchrk's avatar
    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?

    • Abhishek_Soni37's avatar
      Abhishek_Soni37
      Contributor

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

      • nchrk's avatar
        nchrk
        New Contributor II
        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