Capture backslashes of string in tMap for delimited file output

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.

 

Twelve 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!