Link to home
Start Free TrialLog in
Avatar of mitesh114
mitesh114

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of redpipe
redpipe
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theGhost_k8
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:- https://www.experts-exchange.com/questions/21005226/How-to-manipulate-file-names.html?query=file+name+parts+rename+files+string+manipulation&clearTAFilter=true)



Avatar of mitesh114
mitesh114

ASKER

Thanks guys; appreciate your help
the string class has its own Replace method, you can use that:

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