Removing specific letters from a string

Hi,

I have a string which is as follows; name_thumb.jpg

What I want to do is remove the _thumb part of the string so it reads name.jpg.  How can I do this?

Mitesh
mitesh114Asked:
Who is Participating?
 
redpipeConnect With a Mentor Commented:
You can use regex:
string newName = Regex.Replace(oldName, "_thumb", "");
0
 
K VDatabase ConsultantCommented:
Eazy way out is:
      check this sample:
        Dim a As String = "A_thumb.txt"
        a = a.Replace("_thumb", "")
        MsgBox(a)

OR

use mid funtion
check this sample which will do task:-
to read in files named with a format of nnnnnn.nnnnnn_xx and strip out the (.) and add a(.dxf) extension.
Private Sub Command1_Click()
    Dim objFSO As New FileSystemObject
    Dim objFolder As Folder
    Dim objFile As File
    Dim strNewFileName As String
    Set objFolder = objFSO.GetFolder("C:\Testing")  'Repalce the path with your path
    For Each objFile In objFolder.Files
        strNewFileName = Mid(objFile.Name, 1, 6) & Mid(objFile.Name, 8) & ".dxf"
        objFile.Name = strNewFileName
    Next
End Sub
(Source:- http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21005226.html?query=file+name+parts+rename+files+string+manipulation&clearTAFilter=true)



0
 
mitesh114Author Commented:
Thanks guys; appreciate your help
0
 
Ravi SinghSenior Software EngineerCommented:
the string class has its own Replace method, you can use that:

string currentName = "name_thumb.jpg";
string newName = currentName.Replace("_thumb", string.Empty);
0
All Courses

From novice to tech pro — start learning today.