Strip leading / trailing whitespace from strings in DTS Visual Basic Transformation script

Hello,

I have the attached ActiveX script that imports data into my table. The problem I am encountering is that the source data (a text file) contains leading a ASCII character 160 at the start of each value. Unfortunately, the TRIMs do not remove these characters. Is it possible to get rid of these in the transformation script? If so, how? I am a novice when it comes to ActiveX, so detailed assistance is appreciated. Please let me know if any additional detail is required.
'**********************************************************************
'  Visual Basic Transformation Script
'  Copy each source column to the
'  destination column
'************************************************************************
 
Function Main()
	DTSDestination("run_dt") = TRIM(CDATE(DTSSource("Col001")))
	DTSDestination("region_cd") = UCASE(TRIM(DTSSource("Col002")))
	DTSDestination("location_cd") = TRIM(DTSSource("Col003"))
	DTSDestination("area_cd") = UCASE(TRIM(DTSSource("Col004")))
	DTSDestination("rep_id") = UCASE(TRIM(DTSSource("Col005")))
	DTSDestination("order_num") = TRIM(DTSSource("Col006"))
	DTSDestination("order_type") = UCASE(TRIM(DTSSource("Col007")))
	DTSDestination("mobile_num") = TRIM(DTSSource("Col008"))
	DTSDestination("manager_id") = UCASE(TRIM(DTSSource("Col009")))
	DTSDestination("e_cd") = UCASE(TRIM(DTSSource("Col010")))
	DTSDestination("item_cd") = UCASE(TRIM(DTSSource("Col011")))
	DTSDestination("item_dt") = TRIM(CDATE(DTSSource("Col012")))
	DTSDestination("customer_name") = UCASE(TRIM(DTSSource("Col013")))
	DTSDestination("add_offer") = UCASE(TRIM(DTSSource("Col014")))
	DTSDestination("disc_amt") = TRIM(DTSSource("Col015"))
	DTSDestination("retail_amt") = TRIM(DTSSource("Col016"))
	DTSDestination("remarks") = LCASE(TRIM(DTSSource("Col017")))
	DTSDestination("disc_desc") = UCASE(TRIM(DTSSource("Col018")))
	Main = DTSTransformStat_OK
End Function

Open in new window

LVL 1
austerhausAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve HoggITCommented:
You could also use the REPLACE function to change the unwanted char to an empty string.
0
Steve HoggITCommented:
DTSDestination("customer_name") = REPLACE(UCASE(TRIM(DTSSource("Col013"))),Chr(160),"")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
austerhausAuthor Commented:
Thank you for the fast reply. It seems that there are errors thrown when a value is null. However, I was able to get around that using:

IF ISNULL(DTSSource("Col008").value) THEN
        DTSDestination("mobile_num") = "0000000000"
    ELSE
        DTSDestination("mobile_num") = REPLACE(TRIM(DTSSource("Col008")), CHR(160), "")
        END IF

Can you tell me if that is the optimal thing to do?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Steve HoggITCommented:
Is this optimal, i guess that depends on the number of records. It could be quicker to remove the spaces and unwanted characters in the transformation but this is fine.
0
austerhausAuthor Commented:
I am not sure what you mean by "remove the spaces and unwanted characters in the transformation". The code I posted (see below) is contained in the transformation script. Am I missing something?

...
DTSDestination("customer_name") = REPLACE(UCASE(TRIM(DTSSource("Col013"))),Chr(160),"")
IF ISNULL(DTSSource("Col008").value) THEN
        DTSDestination("mobile_num") = "0000000000"
    ELSE
        DTSDestination("mobile_num") = REPLACE(TRIM(DTSSource("Col008")), CHR(160), "")
        END IF
....
0
Steve HoggITCommented:
Oh, sorry. I don't why I was thinking it was an ActiveX script. This is good the way you have it. I can't think of a better way.
0
austerhausAuthor Commented:
Great, thank you for the assistance!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.