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
Solved

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

Posted on 2013-05-22
2
583 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

765 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