Solved

Removing specific letters from a string

Posted on 2006-10-26
4
190 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
Comment Utility
You can use regex:
string newName = Regex.Replace(oldName, "_thumb", "");
0
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
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
Comment Utility
Thanks guys; appreciate your help
0
 
LVL 18

Expert Comment

by:Ravi Singh
Comment Utility
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now