Solved

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

Posted on 2007-11-28
11
728 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 500 total points
ID: 20367259
use chr(42) instead of *
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 50
how to check mis-spellings in a select SQL 2 39
Record locking on classic ASP 3 41
Connect Gridview column to Textbox in C# 2 42
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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