Hi , I am not sure what is the correct syntax for the substring and the instr used in the tmap component of talend. I the string coming in the format like below:- "Anatasio::50.00,Received" Now I just need to extract 50.00 from the above sting not sure what is the correct syntax i will use in tmap component. Please help on this
You have to use the Java language: row1.my_string.substring(row1.my_string.indexOf("::")+2, row1.my_string.indexOf(",")) returns your 50.00 value as String If you need this as number: Double.valueOf(row1.my_string.substring(row1.my_string.indexOf("::")+2, row1.my_string.indexOf(",")))
Thanks that works perfectly fine. Just one more question if I need to apply the if else condition also. For eg. I have my incoming sting in two format:- "Anatasio::50.00,Received" "Michael wasnowaski ::70" So I need to apply the condition if my input sting has ', ' then (Double.valueOf(row1.my_string.substring(row1.my_string.indexOf("::")+2, row1.my_string.indexOf(",")))) else other function So how do I write the if else function in the tmap component for this.
You can do this with the ? operator. <condition> ? <expression for true> : <expression for false> You could also consider using regulary expressions. But this field is probably only useful if you decide to get deeper knowledge about that.
Hi Lucian, There is no straight forward way to do it using talend component, but you can easily do it it using Java way. 1) Import and use http://commons.apache.org/proper/commons-io/download_io.cgi commons-io.jar file using tlibrary load 2) Import library import org.apache.commons.io.FilenameUtils; or copy jar file in lib folder and restart talend 3) in Tjava use following code String foo = "http://www.mydomain-1.com/a/b/c/image1.jpg"; String baseName = FilenameUtils.getBaseName(foo); String extension = FilenameUtils.getExtension(foo); System.out.println("file name is : " + baseName+"."+extension); I think you got an idea, change your code to fit your requirement. Thanks Vaibhav