Q:

Delete specific symbol and number at the end of filename if exist

My application is downloading many diffrent files from network. There is possibility that some of the files could contain additional number within brackets like below:
 report78-12-34-34_ex                                  'nothing to be removed 
 blabla3424dm_d334(7)                                  '(7) - to be removed
 erer3r3r3_2015_03_03-1945-user-_d334(31).xml          '(31) - to be removed 
 group78-12-34-34_ex.html                              'nothing to be removed
 somereport5_6456                                       'nothing to be removed

As you see if (number) appear within filename it has to be removed. Do you have some nice secure method which could do the job?
I got some code from rakesh but it is not working when string doesn't contain (number):
string test="something(3)";
test=Regex.Replace(test, @"\d", "").Replace("()","");

Not working when e.g:
if i place file like this: UIPArt3MilaGroupUIAPO34mev1-mihe-2015_9_23-21_30_5_580.csv then it will show: UIPArtMilaGroupUIAPOmev-mihe--_.csv
And i would prefer not using regex.

A:

Avoids Regex and checks the string inside the parentheses, only removing the substring if the enclosed string is a number.
Private Function NewFileName(ByVal FileName As String) As String
    If FileName Like "*(*)*" Then
        Try
            Dim SubStrings() As String = Split(FileName, "(", 2)
            NewFileName = SubStrings(0)
            SubStrings = Split(SubStrings(1), ")", 2)
            SubStrings(0) = NewFileName(SubStrings(0))
            SubStrings(1) = NewFileName(SubStrings(1))
            If IsNumeric(SubStrings(0)) Then
                NewFileName &= SubStrings(1)
            Else
                Return FileName
            End If
        Catch
            Return FileName
        End Try
    Else
        Return FileName
    End If
End Sub

