[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

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
0
mitesh114
Asked:
mitesh114
1 Solution
 
redpipeCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now