?
Solved

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

Posted on 2007-11-28
11
Medium Priority
?
730 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
[X]
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
  • 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 2000 total points
ID: 20367259
use chr(42) instead of *
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

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