[resolved] Need to modify string of numbers and characters from ####CR to -####

One Star

[resolved] Need to modify string of numbers and characters from ####CR to -####

Looking for a component or configuration of one to do the task of change numeric value with a CR at the end to be a negative number with the " - " at the beginning of the number. so 32455CR would be converted to -32455. This occurs in several columns, so It would need to be repeatable.

Accepted Solutions
Community Manager

Re: [resolved] Need to modify string of numbers and characters from ####CR to -####

Hello
You can transform it on tMap, eg;
tFileInput--row1--tMap---tLogRow
type in expression of output column as:
row1.columnName.contains("CR")?"-"+row1.columnName.substring(0,row1.columnName.indexOf("CR")):"-"+row1.columnName

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] Need to modify string of numbers and characters from ####CR to -####

Hello
You can transform it on tMap, eg;
tFileInput--row1--tMap---tLogRow
type in expression of output column as:
row1.columnName.contains("CR")?"-"+row1.columnName.substring(0,row1.columnName.indexOf("CR")):"-"+row1.columnName

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Need to modify string of numbers and characters from ####CR to -####

This works great, I just needed to remove the last "-" and replace it with a " " and then the conversion ran perfectly. Thanks for taking the time to respond to my post.
One Star

Re: [resolved] Need to modify string of numbers and characters from ####CR to -####

How about when you want to remove non digit characters and leave numbers only but not remove the . sign for numbers with decimals e.g. 3.5 ml and .6ml . i have used the replace function (\\D) but the thing is it removes the . on these type of numbers so the result is 3 5 and 6 instead of .6 and 3.5
Your help will be much appreciated
One Star

Re: [resolved] Need to modify string of numbers and characters from ####CR to -####

Try this in tmap. It will replace all letters and spaces.
row1.a.replaceAll("","").replaceAll(" ","")
Regards,
Rick