Replacing * in a VB.NET String

Nathan Sokalski 4,116 Reputation points
2020-06-15T22:49:58.967+00:00

I'm not sure if this is the right place to ask this, but here is my question. I have a String in VB.NET which may contain the String "1*", and I would like to replace this with "*". I have tried using the Replace method of String, as well as the Replace & Escape methods of RegEx, but none of them seem to work. Neither of the following seemed to work:

.Replace("1*", "*")

.Replace("1*", "*")

And I tried several different combinations of the RegEx methods, but still no success. What should I be doing? Thanks.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,002 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nathan Sokalski 4,116 Reputation points
    2020-06-16T02:45:53.633+00:00

    I found the problem, and it was not really a problem at all, just one of those stupid mistakes that we sometimes make. I was using the wrong variable in my code, and therefore I was looking for the wrong answer! Embarrasing to admit, so if you were trying to find what was wrong, don't bother, because nothing was wrong (well, nothing that applies to this post)! But thank you to all that tried to help me!

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Dave Patrick 426.1K Reputation points MVP
    2020-06-15T22:52:38.507+00:00

    They're actively answering VB.Net question in dedicated forums here.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    --please don't forget to Accept as answer if the reply is helpful--


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    0 comments No comments

  2. Ken Tucker 5,846 Reputation points
    2020-06-15T23:51:24.413+00:00

    The replace method returns a new string with the changed text

                Dim str = "1235".Replace("1", "*")
    

    It is the same for regex.replace

    0 comments No comments