Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Removing specific letters from a string

Posted on 2006-10-26
4
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Accepted Solution

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

Expert Comment

by:K V
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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