Solved

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

Posted on 2007-11-28
11
727 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 

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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

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…
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

861 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