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?
 
HoggZillaConnect With a Mentor Commented:
DTSDestination("customer_name") = REPLACE(UCASE(TRIM(DTSSource("Col013"))),Chr(160),"")
0
 
HoggZillaCommented:
You could also use the REPLACE function to change the unwanted char to an empty string.
0
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
HoggZillaCommented:
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
 
HoggZillaCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.