cancel
Showing results for 
Search instead for 
Did you mean: 

Stripping Out Carriage Returns

Former Member
0 Kudos

Hi,

Hopefully an easy answer to this one!

How do you strip out carriage return characters from a field on the outbound payload during mapping? I am assuming you use the replaceString function but what value would you use to represent the Carriage Return in the first of the two Constants needed in a replaceString?

Cheers,

PaulC.

Accepted Solutions (0)

Answers (3)

Answers (3)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>but what value would you use to represent the Carriage Return in the first of the two Constants needed in a replaceString?

First constant uses  "\n"  or "\r"  or both "\n\r" (Depends on what you get in the payload)

Second constant uses  " "       (empty string)

otherwise write a simple udf

String s1 = "this\r\nis a test";

String s2 = s1.replaceAll("[\n\r]", "");

Hope this helps.

rajasekhar_reddy14
Active Contributor
0 Kudos

1 st argument source field.

Above example replaces 1 with 2.

Former Member
0 Kudos

Yes, but my question is what value do you put in the first constant field to represent a Carriage Return. Is it something like CHR(13) i.e. ascii code 13.

Cheers,

PaulC.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Paul,

               According to ASCII table carriage return has decimal value 13. You can use below UDF to remove any character based on its ASCII value.

Here ascii variable is used to hold ASCII value of the character to be removed.

public static String removeCR(String s)

{

       int i,l,ascii=13;

       String a="";

       if(s!=null && !s.equals(""))

       {

             for(i=0,l=s.length();i<l;++i)

             {

                   if((int)s.charAt(i)!=ascii)

                   {

                         a=a+s.charAt(i);

                   }

            }

             s=a;

       }

       return s;

}

Regards

Anupam

Message was edited by: Anupam Ghosh

Former Member
0 Kudos

Apologies, but due this topic being approved for moderation hours after I posted it the topic has never appeared on the first page i.e. nobody has probably seen it!!

MEMO to mods: Stick approved topics at the top of page 1 to give them a chance !!!