Capture backslashes of string in tMap for delimited file output

Highlighted
Six Stars

Capture backslashes of string in tMap for delimited file output

I have a job where i am capturing two string fields into tMap. The first field is called fileInput_XML which is defined as a String. It holds an XML document in String format. The second field is called abs_path holds (String)globalMap.get("tFileList_1_CURRENT_FILEPATH") which is the filepath and filename of the xml document.  In tMap i am doing the following in an variable called var1 to add the abs_path into the fileInput_XML string value. 

 

StringHandling.EREPLACE(row1.fileInput_XML,"<head>", "<head><abs_path>" + row1.abs_path + "</abs_path>"

 

When I output the var1's content from tMap to tFileOutputDelimited the output has the filepath and filename details but the \ of the filepath is missing. In other words I was expecting the filepath  to be  C:\data\file1.xml  but the output file has the following C:datafile1.xml. 

 

How do i capture the backslashes in the output?

 

Appreciate your help. Thanks.


Accepted Solutions
Ten Stars

Re: Capture backslashes of string in tMap for delimited file output

String x="<x> <head/> </x>";
System.out.println(x);
String newx=StringHandling.EREPLACE(x, "\\<head/>","\\<head/>C\\:\\\\folder\\\\subfolder\\\\x.txt \\</head>");
System.out.println(newx);

Regex escaping... not just normal string escaping.

 

Six Stars

Re: Capture backslashes of string in tMap for delimited file output

Used the following in my Tmap Variable to overcome the problem. 

StringHandling.EREPLACE(row1.fileInput_XML,"<head>", "<head><abs_path>" + StringHandling.EREPLACE(row1.abs_path, "\\\\","\\\\\\\\") + "</abs_path>"   .  This help me get the following output <head> <abs_path> C:\data\file1.xml </abs_path></head>

 

Thanks for your pointer Dijke!


All Replies
Ten Stars

Re: Capture backslashes of string in tMap for delimited file output

String x="<x> <head/> </x>";
System.out.println(x);
String newx=StringHandling.EREPLACE(x, "\\<head/>","\\<head/>C\\:\\\\folder\\\\subfolder\\\\x.txt \\</head>");
System.out.println(newx);

Regex escaping... not just normal string escaping.

 

Forteen Stars

Re: Capture backslashes of string in tMap for delimited file output

You can use on windows Linux style format for path:

Screen Shot 2018-05-22 at 14.29.41.png]

 

 

in this case all must work with You formula:

 

Screen Shot 2018-05-22 at 14.32.13.png

Screen Shot 2018-05-22 at 14.32.18.png

 

-----------
Six Stars

Re: Capture backslashes of string in tMap for delimited file output

Used the following in my Tmap Variable to overcome the problem. 

StringHandling.EREPLACE(row1.fileInput_XML,"<head>", "<head><abs_path>" + StringHandling.EREPLACE(row1.abs_path, "\\\\","\\\\\\\\") + "</abs_path>"   .  This help me get the following output <head> <abs_path> C:\data\file1.xml </abs_path></head>

 

Thanks for your pointer Dijke!

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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

Downloads and Trials

Test drive Talend's enterprise products.

Downloads