cancel
Showing results for 
Search instead for 
Did you mean: 

CDATA newLine issue

Former Member
0 Kudos

Hi gurus

we have an issue regarding newLines in CDATA like following example;

<comment><![CDATA[position-text 

line 2 text line 2

line 3 no.:  870011 ]]></comment>

and need to remove the newlines so that we send everything in a single line.

<comment><![CDATA[position-text line 2 text line 2 line 3 no.:  870011 ]]></comment>

i tried with replace string and trim function without success.

can anyone help me?

Regards

PM

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Peter,

                 you can try this UDF. I tested this in my system, it was able to remove newlines and carriage returns from CDATA section.

public String removeNewline(String s,Container container){

try

  {

   String a="";

   int l=s.length();

   for(int i=0;i<l;++i)

   {

    if(s.charAt(i)=='\n' || s.charAt(i)=='\r')

    {

     continue;

    }

    a=a+s.charAt(i);

   }

   s=a;

  }

  catch(Exception e)

  {

   e.printStackTrace();

  }

  return s;

}

Alternatively you can use this code

public String removeNewline(String s,Container container){

try

  {

  

   s=s.replaceAll("\n", "");

   s=s.replaceAll("\r","");

 

  }

  catch(Exception e)

  {

   e.printStackTrace();

  }

  return s;

Regards

Anupam

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi.  Peter.

You can try a simple sentence in your UDF.

Variable:var1

return var1.replace("\n", "");

Regards

Lucho.