Solved

how to remove a hyphen from a string in vb.net?

Posted on 2013-05-22
2
576 Views
Last Modified: 2013-05-22
Hello,

I have a string like At --- 153 and i need to get rid of this hyphens(---) and get the string as
AT 153,  How Can I achieve this in vb.net ? Thanks!
0
Comment
Question by:developer2012
2 Comments
 
LVL 23

Assisted Solution

by:tailoreddigital
tailoreddigital earned 250 total points
ID: 39189272
http://www.dotnetperls.com/replace-vbnet


Based on their example you could,

Module Module1
    Sub Main()
      ' Assign string to reference.
      Dim value1 As String = "At --- 153"
      Console.WriteLine(value1)

      ' Replace word with another word.
      Dim value2 As String = value1.Replace("---", "")
      Console.WriteLine(value2)
    End Sub
End Module
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 39189341
Another way...this splits on both space and hyphen, then re-joins it back together so that you end up with just one space in the end:
        Dim str As String = "At --- 153"
        str = String.Join(" ", str.Split("- ".ToCharArray, StringSplitOptions.RemoveEmptyEntries))
        Debug.Print(str)

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
Reading the Web.Config using IIS 7.5? 4 35
Where did System.Data.Objects go? 2 23
Dot Net 4.6.1 installation fails on W2012 R2 server 14 15
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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