【问题标题】:How to remove a set string pattern in SSIS?如何在 SSIS 中删除设置的字符串模式?
【发布时间】:2009-01-16 17:58:32
【问题描述】:

我想修改一个字符串。在 ssis 中,我有一个步骤是“派生列转换编辑器”。我有一个字符串,例如:

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

我想删除“~~StringIWantToRemove” “~~”是分隔符 "StringIWantToRemove" 是任意值的随机字符串(分隔符除外)

我会尝试查找 ~~ 的索引,然后查找字符串的 len,然后从该点删除,但不确定如何在 ssis 中执行此操作。

帮助?

【问题讨论】:

    标签: sql-server string ssis


    【解决方案1】:

    我会考虑使用带有正则表达式的脚本任务 - 这可能比尝试将其提炼成派生列任务中的单行更容易。

    【讨论】:

    • 我尝试做 SUBSTRING(trackingCode,1,FINDSTRING(trackingCode,"~~",1) - 1) 上面的问题是“-1”
    • 我不认为 -1 是你的问题。我认为您的问题是 FINDSTRING(trackingCode,"~~",1) 返回 0,因为它没有找到您的搜索字符串。
    【解决方案2】:

    最后我使用了一个脚本组件:

    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
    

    【讨论】:

      猜你喜欢
      • 2014-10-31
      • 1970-01-01
      • 2022-12-03
      • 2011-09-28
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 2014-03-15
      相关资源
      最近更新 更多