Solved

Removing specific letters from a string

Posted on 2006-10-26
4
193 Views
Last Modified: 2010-04-16
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
Comment
Question by:mitesh114
4 Comments
 
LVL 8

Accepted Solution

by:
redpipe earned 250 total points
ID: 17810031
You can use regex:
string newName = Regex.Replace(oldName, "_thumb", "");
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 17810036
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
 

Author Comment

by:mitesh114
ID: 17810389
Thanks guys; appreciate your help
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17810390
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question