Question Replace List of Special Characters

Brittney10

New member
Joined
Dec 10, 2012
Messages
1
Programming Experience
Beginner
Hello! I'm relatively new to programming and I use VB.NET in SSIS and every now and then when I need a custom script task to perform a task with the data given. I'm trying to remove special characters from a column. I'm close, but can't get the script to remove only characters from the list I've given it.


The below works (so i know I'm close!)
VB.NET:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

        Dim pattern As String = String.Empty

        Dim r As Regex = Nothing
        pattern = "[^a-zA-Z0-9 ]" 
        r = New Regex(pattern, RegexOptions.Compiled)
        Row.MYCOLUMNREPLACE= CStr(Regex.Replace(Row.MYCOLUMN, pattern, "")) 'replace special chars with empty space
        Row.MYCOLUMNREPLACE= CStr(Regex.Replace(Row.MYCOLUMN, pattern, "")) 'replace special chars with empty space
        'End If

    End Sub

However, I'm only needing to replace this list of speical characters [!@#$%^&*_+=,]. When i try the code below instead, it does not work.

VB.NET:
pattern = "[!@#$%^&*_+=,]"

Thanks for your help (and patience with me...I'm new at this!)

-B
 
I don't think you would require Regex to do this though. You could have a string of characters, and loop through them to Replace them with string.empty.
 
Back
Top