Solved

How to remove the symbol "*" using string.remove function

Posted on 2007-11-28
11
724 Views
Last Modified: 2008-02-01
Hi,

I was trying to munipulate a string using the Remove function to get rid of the "*".

myString.Remove(myString.IndexOf("*"), 1)

It doesn't post any errors, but just won't remove the "*", I guess it has something to do with the wildcard, but not very sure, can anyone help?

thanks
While myString.IndexOf("*") >= 0

   myString = myString.Remove(myString.IndexOf("*"), 1)

End While

Open in new window

0
Comment
Question by:CRIIT
  • 5
  • 5
11 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20367233
The code you posted works, but this might be a little more efficient.

Dim myString2 As String = "test***test"

myString2 = myString2.Replace("*", String.Empty)

Open in new window

0
 

Author Comment

by:CRIIT
ID: 20367252
i tried my code, it didn't work, it worked with any other symbols, like: #, @, +, but just not *.
0
 
LVL 3

Accepted Solution

by:
cforant earned 500 total points
ID: 20367259
use chr(42) instead of *
0
 

Author Comment

by:CRIIT
ID: 20367330
great, that's what exactly i am looking for, thanks a lot
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20367425
The question is why?  Doesn't make sense to me.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:CRIIT
ID: 20367442
i don't know why, but if you try, i will see
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20367488
I have tried it... both these methods yield a string "testtest"


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim myString As String = "test***test"
        myString = myString.Replace("*", String.Empty)
        MsgBox(myString)

        'reset
        myString = "test***test"
        While myString.IndexOf("*") >= 0
            myString = myString.Remove(myString.IndexOf("*"), 1)
        End While
        MsgBox(myString)

    End Sub
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20367498
There isn't any difference here:


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim myString As String = "test***test"
        myString = myString.Replace("*", String.Empty)
        MsgBox(myString)

        'reset
        myString = "test***test"
        While myString.IndexOf("*") >= 0
            myString = myString.Remove(myString.IndexOf("*"), 1)
        End While
        MsgBox(myString)


        'reset
        myString = "test***test"
        While myString.IndexOf(Chr(42)) >= 0
            myString = myString.Remove(myString.IndexOf(Chr(42)), 1)
        End While
        MsgBox(myString)

        myString = "test***test"
        myString = myString.Replace(Chr(42), String.Empty)
        MsgBox(myString)

    End Sub
0
 

Author Comment

by:CRIIT
ID: 20367506
en..., that's interesting, it doesn't work (getting rid of the *) on my machine. I am running it on framework 1.1. i wouldn't post the question if it works. But I do appreciate your input.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20367765
>I am running it on framework 1.1

I just tested it on that framework... the code I posted works as I said.  Since Chr(42) is exactly the same as * it just doesn't make sense for it not to work.

I'm hoping cforant can shed some light on why he made that suggestion, because it has me stumped.
0
 

Author Comment

by:CRIIT
ID: 20367924
yeah, i am puzzled too.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

9 Experts available now in Live!

Get 1:1 Help Now