views:

471

answers:

2

Hi

i wish to modify a string. In ssis I have a step which is a "Derived column transformation editior". I have a string such as:

edit=style?form=exy?test=x~~StringIWantToRemove

I wish to remove "~~StringIWantToRemove" "~~" is the delimiter "StringIWantToRemove" is a random string og any value (apart from the delimiter)

I would try find index of ~~ then len of string then remove from that point but not sure how to do it in ssis.

help?

+1  A: 

I would consider using a script task with a regex - it's probably easier than trying to distill it down into a one-liner in a derived column task.

Cade Roux
I tried to doSUBSTRING(trackingCode,1,FINDSTRING(trackingCode,"~~",1) - 1)the problem with the above is the "-1"
Joe
I don't think that -1 is your problem. I think your problem is that FINDSTRING(trackingCode,"~~",1) is returning 0 because it's not finding your search string.
Cade Roux
A: 

in the end I used a script component:

Dim debugOn As Boolean
debugOn = False

If debugOn Then MsgBox(Row.trackingCode)
If Row.trackingCode <> "" Then
    ' find the delimiter location
    Dim endLocation As Integer
    If debugOn Then MsgBox("index of ~~ is " & Row.trackingCode.ToString().IndexOf("~~", 0))
    ' chk if we have ~~ in field, if not in field then -1 is returned
    If Row.trackingCode.ToString().IndexOf("~~", 0) > -1 Then
        ' if ~~ at the beginning ie no tracking code
        If Row.trackingCode.ToString().IndexOf("~~", 0) = 1 Then
            endLocation = Row.trackingCode.ToString().IndexOf("~~", 0)
        ElseIf Row.trackingCode.ToString().IndexOf("~~", 0) > 1 Then
            endLocation = Row.trackingCode.ToString().IndexOf("~~", 0) - 1
        End If
        If debugOn Then MsgBox("end of track code is " & endLocation)
        Row.trackingCode = Row.trackingCode.Substring(1, endLocation)
    End If
End If
Joe