replaceAll("[\\x32\\x0A\\x0D]", "") - what does this mean?

Seven Stars

replaceAll("[\\x32\\x0A\\x0D]", "") - what does this mean?

Hi,

 

I would like to understand what row1.line.replaceAll("[\\x32\\x0A\\x0D]","").replaceAll(" ","") means in tMap.

 

Thanks in advance

 


Accepted Solutions
Nine Stars

Re: replaceAll("[\\x32\\x0A\\x0D]", "") - what does this mean?

Hi,

 

row1.line is probably a String.

replaceAll(String regex, String replacement) is a String method

It returns a String replacing each substring matching the regular expression regex with the replacement text.

For example :

 

"Hello World!".replaceAll("o","0")

Will produce :

"Hell0 W0rld!"

That being said, your code is :

row1.line.replaceAll("[\\x32\\x0A\\x0D]","").replaceAll(" ","")

Which will first replace all occurences of "[\\x32\\x0A\\x0D]" in row1.line by an empty string "" (ie.: remove all occurences of "[\\x32\\x0A\\x0D]"; this is a regular expression matching any caracters 0x32, 0x0a or 0x0d which are respectively the digit 2, the carriage return and the line feed caracters).

And then, replace all occurences of " " by an empty string "" (ie.: remove also all spaces) in the resulting string.

 

In the end, this code will replace all spaces, carriage returns, line feeds and digits 2 from the input data.

Please note that removing spaces and new lines or carriage returns is common, but removing the digit 2 is not Smiley Wink

 

Please also note that I see no reason to not use this instead :

row1.line.replaceAll("[2\r\n ]","")

Regards.


All Replies
Nine Stars

Re: replaceAll("[\\x32\\x0A\\x0D]", "") - what does this mean?

Hi,

 

row1.line is probably a String.

replaceAll(String regex, String replacement) is a String method

It returns a String replacing each substring matching the regular expression regex with the replacement text.

For example :

 

"Hello World!".replaceAll("o","0")

Will produce :

"Hell0 W0rld!"

That being said, your code is :

row1.line.replaceAll("[\\x32\\x0A\\x0D]","").replaceAll(" ","")

Which will first replace all occurences of "[\\x32\\x0A\\x0D]" in row1.line by an empty string "" (ie.: remove all occurences of "[\\x32\\x0A\\x0D]"; this is a regular expression matching any caracters 0x32, 0x0a or 0x0d which are respectively the digit 2, the carriage return and the line feed caracters).

And then, replace all occurences of " " by an empty string "" (ie.: remove also all spaces) in the resulting string.

 

In the end, this code will replace all spaces, carriage returns, line feeds and digits 2 from the input data.

Please note that removing spaces and new lines or carriage returns is common, but removing the digit 2 is not Smiley Wink

 

Please also note that I see no reason to not use this instead :

row1.line.replaceAll("[2\r\n ]","")

Regards.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

APIs for Dummies

View this on-demand webinar about APIs....

Watch Now