One Star

How to concatenate string with filter in tmap

Hi,
I have a date column like
02/23/2013
04/23/2013
02-23-2014
dates are in different format so to take the column in one format (MM-dd-YYYY) i used tReplace and replaced "/" with "-"
but know the output dates which are replaced are like for 02/23/2013 output is 2-23-2013 so
How do I concatenate a "0" to all the dates which are converted .
6 REPLIES
One Star

Re: How to concatenate string with filter in tmap

If your input field is of type string, you shouldn't have to have the issue you're having... The replace shouldn't remove leading zeros... See attached...
(Alternatively, you can use a java date parse function to convert what you currently have...)
Seventeen Stars

Re: How to concatenate string with filter in tmap

hi,
as you need to know which pattern is used before replace caracter, you can try the tFilterRow in advenced mode and check String contains "-" ; if OK do something
Else , use reject flow , check if contains "/" ....etc
here an example to convert String to Date without using too many java code by Talend components. (it will be more readable Smiley Happy
regards
laurent
One Star

Re: How to concatenate string with filter in tmap

@kzone - I like your solution as well, but want to point out that the replace function will only replace if it finds a delimiter - so the code is lighter - no need for filtering for it... Sometimes leveraging java functions is more efficient and equally elegant...
If my example seemed like overkill (and overwhelming), here's the output field that should work for all fields:
(strDate1.toString()).replace("/", "-")
It first makes sure it's a String, then replace any occurences of / with -
Seventeen Stars

Re: How to concatenate string with filter in tmap

It's not the fact that java code is more elegant or not Smiley Wink
Using 'Talend graphic langage', I'm able to also use any statistics information about meterflow or catch reject about filter, etc.
If I have some evolutions or modifications, I can easily do it by adding some extra "Talend code".
By using java code, I have to add some new extra java code to modify behavior.
In my example, I've got some java code with contain method, but inherent to filter component.
It's one of reasons that I'm using java code as few as possible even if it could be elegant Smiley Happy
But it's not a priesthood Smiley Wink
regards
laurent
One Star

Re: How to concatenate string with filter in tmap

Thanks Willm and kezone !!!
@willm my input field is string and I use tReplace component to replace the "/" with "-" but actually i missed to mention that my source column did not had leading zeros for dates with "/" format.
but I used a different solution : After replacing the "/" with "-" . In tMap I used an expression as below which worked !!!
(row3.Date.length())==9)?"0"+row3.Date : row3.Date
One Star

Re: How to concatenate string with filter in tmap

Awesome, pkakade! Glad you got it to work...
kzone - I totally understand what you're saying about using Talend out-of-the-box components and methods than using Java... I hear you... Yes, when you need to expose stats, Talend components are the way to go. My suggestion of that tiny java snippet was intended for the tMap component which doesn't interfere much with things before and after it...
But I agree - data integration is both an art and a science... Smiley Happy