Solved

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

Posted on 2007-11-28
11
725 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 45
Replace &lt; with < 14 57
fso.FolderExists("\\server\HiddenFolder$") 4 52
Exit the loop 4 39
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

20 Experts available now in Live!

Get 1:1 Help Now