Question : SSIS Package - Script Component question - remove leading spaces

I am using an SSIS package in SQL 2005 to transfer data from a Flat File source to an SQL table.
The flat file has an uneven number of columns and as a result I am using a Script Component (Transformation) to put the data in the correct format for the OLE DB destination I am using.

I am using 1 input column for the script component and I am using 17 output columns.
The output columns are all string data types - string [DT_STR]

My problem is that the data that is uploaded to the sql table all have leading spaces.

Is there some way I can use a command like LTRIM (or similar) to remove the leading spaces from the output columns in the script component script that I use before the data is uploaded to the sql table?

See the following for the script that I use;

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

        Row.Col1 = Tokenise(Row.Column0, ";", 1)
        Row.Col2 = Tokenise(Row.Column0, ";", 2)
        Row.Col3 = Tokenise(Row.Column0, ";", 3)
        Row.Col4 = Tokenise(Row.Column0, ";", 4)
        Row.Col5 = Tokenise(Row.Column0, ";", 5)
        Row.Col6 = Tokenise(Row.Column0, ";", 6)
        Row.Col7 = Tokenise(Row.Column0, ";", 7)
        Row.Col8 = Tokenise(Row.Column0, ";", 8)
        Row.Col9 = Tokenise(Row.Column0, ";", 9)
        Row.Col10 = Tokenise(Row.Column0, ";", 10)
        Row.Col11 = Tokenise(Row.Column0, ";", 11)
        Row.Col12 = Tokenise(Row.Column0, ";", 12)
        Row.Col13 = Tokenise(Row.Column0, ";", 13)
        Row.Col14 = Tokenise(Row.Column0, ";", 14)
        Row.Col15 = Tokenise(Row.Column0, ";", 15)
        Row.Col16 = Tokenise(Row.Column0, ";", 16)
        Row.Col17 = Tokenise(Row.Column0, ";", 17)
    End Sub

    'Private function that parses out the columns of the whole row

    Private Function Tokenise(ByVal input As String, ByVal delimiter As String, ByVal token As Integer) As String
        Dim tokenArray As String()
        tokenArray = input.Split(delimiter.ToCharArray) 'Split the string by the delimiter
        If tokenArray.Length < token Then 'Protect against a request for a token that doesn't exist
            Return ""
        Else
            Return tokenArray(token - 1)
        End If
    End Function
End Class



Answer : SSIS Package - Script Component question - remove leading spaces

Return tokenArray(token - 1).trim
Random Solutions  
 
programming4us programming4us