PDA

View Full Version : Altering String with JavaScript



kettle_anonymous
04-20-2006, 04:02 AM
Hello,


I load data from a text file, which works pretty well. One field contains a number in the format "+000012,4567", which is not correct (Oracle doesnÂ't like the "+"). I load this field as a string, but now I want to



1. eliminate the "+" from the string and
2. convert the string to a number.



I found the javascript function "replace", but what I do not know is how to use the "Java Script Value"-Transform-Step. How can I assign the value of a field to a java script variable, how can I write the result back to the fiel? Maybe a screenshot would help me most.



Before using spoon I was used to work with external tables. A replace function could easily be integrated in the external table DDL.



I would be very thankful if you could help me with this problem.



Thx in advance.



Dominik

MattCasters
04-20-2006, 04:12 AM
Hi Dominik,

You can do it directly in Text File Input by adding the + to the format mask, in your case:

'+'000000.0000

or perhaps '+'#.# will also work.

As for the replace function:

field.replace("+", "") would do the trick. The value is changed directly on the field value.
For more information on JavaScript, see the Weekly Kettle Tip on JavaScrip from a few weeks ago on this very forum.

HTH,

Matt