cancel
Showing results for 
Search instead for 
Did you mean: 

Remove following characters " \ , # from field and Replace with Space

Former Member
0 Kudos

Dear Team,

This is basically IDOC-FILE(.csv) conversion.

'MATNR' field populates with following special characters which has to be replaced with space.

, # \ "

Please help on this. Thank you very much in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rajesh,

Easiest way to maintain it by using mapping function replaceString.

As we are facing illegal escape character issue while using replaceAll in UDF.

Thanks

Sagarika

former_member186851
Active Contributor
0 Kudos

The same I told Rajesh,If the special characters are less you can do with standard functions only.

Please try both and let us know the results.

Answers (2)

Answers (2)

former_member186851
Active Contributor
0 Kudos

Hello Rajesh,

Try the below code

String Out= Input.replaceAll("[#\]","");

return Out;

add all the required special characters in the square braces

If you will get only # \ then you can use normal mapping functions like replace string and achieve it.

Former Member
0 Kudos

Hi Raghu,

But above code will remove only \ and # and replace with  Space. How about other two mentioned below

, "

former_member186851
Active Contributor
0 Kudos

Rajesh,

Add them also in the braces as I mentioned earlier.

String Out= Input.replaceAll("[#\",]","");

return Out;

Former Member
0 Kudos

Hi Manoj/Raghu

MATNR field contains all 4 special characters mentioned below. For Example:

"FABRIC\32XL#SLK,32

Because of this there is mismatch in rows and columns of the .csv file.

, # \ "

I will try the above mentioned code

manoj_khavatkopp
Active Contributor
0 Kudos

Raghu did you try the code you provided ? did it work ?

Rajesh for me at-least the code provide by Raghu didnt work i tried below approach.


var1 = var1.replaceAll("[#,\"]","");

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

former_member186851
Active Contributor
0 Kudos

Trying the same Manoj.PI system struck..I doubt at " character only

Thanks for trying Manoj.

Manoj ur approach worked?

Rajesh please try and close the thread.

former_member182412
Active Contributor
0 Kudos

Hi Rajesh/Manoj/Raghu,

No need to write the code from scratch, no need to invest the time to write the UDF, check my blog you can use ready made StringUtils functions for this type of requirement.

You can use replacePattern function in above mentioned blog.

Regards,

Praveen.

manoj_khavatkopp
Active Contributor
0 Kudos

Oops i missed your blog , I vote for u !

manoj_khavatkopp
Active Contributor
0 Kudos

Try this :


return var1.replaceAll("[^a-zA-Z0-9]","");

This will replace all the special characters.

Br,

Manoj

Former Member
0 Kudos

    Hi Manoj,

Thanks much for your inputs.

Requirement is specifically for below one's alone which has to be replaced with Space. Other special characters are required are required compulsorily.

, # \ "




manoj_khavatkopp
Active Contributor
0 Kudos

One more query why is the MATNR having special characters ?

This field corresponds to material number if i am not wrong.

former_member190293
Active Contributor
0 Kudos

Hi Manoj!

It's worth mention that your regex will also replace all non-Latin characters as well. One should be very carefull when using this regex.

Regards, Evgeniy.