CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    TX, USA
    Posts
    347

    Replace Chr(32) or "*" with ""

    Can't seem to get either one of these to work:
    I want to replace all "*" with ""

    Code:
    a=replace(a,"*","")
    a=replace(a,chr(42),"")
    
    m=""
    for i=1 to len(a)
      t=mid(a,i,1)
      if t<>"*" then m=m+t    (tried chr(32) here also
    next i
    Two hours spent here...
    Last edited by nbCathy; September 30th, 2004 at 10:51 AM. Reason: used wrong code number or *
    Cathy
    Jan 2004 - NEWBIE to VB6
    Any and all help appreciated

  2. #2
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249

    Re: Replace Chr(32) or "*" with ""

    Hmmm ...

    Dim TmpString As String

    TmpString="ABCD*EFGH*JIKLM*NOPQR*STUV*WXYZ*"

    TmpString=Replace(TmpString,"/*","")

    Should work ... I think it may have to do with VB treating the "*" as a wildcard. Try escaping it.

  3. #3
    Join Date
    Jan 2004
    Location
    TX, USA
    Posts
    347

    Re: Replace Chr(32) or "*" with ""

    Nope. didn't work. Seems as if Replace isn't replacing anything right now.
    I'm sort of new. What do you mean by the "escaping it"
    tks
    Cathy
    Jan 2004 - NEWBIE to VB6
    Any and all help appreciated

  4. #4
    Join Date
    Sep 2004
    Location
    Sandhem, Sweden
    Posts
    20

    Re: Replace Chr(32) or "*" with ""

    Instead of doing it like this:
    TmpString=Replace(TmpString,"/*","")

    Do the same but skip the slash.
    TmpString=Replace(TmpString,"*","")

    This works for sure.

    Regards,
    Michael

  5. #5
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249

    Re: Replace Chr(32) or "*" with ""

    Quote Originally Posted by MichaelNattfalk
    Instead of doing it like this:
    TmpString=Replace(TmpString,"/*","")

    Do the same but skip the slash.
    TmpString=Replace(TmpString,"*","")

    This works for sure.

    Regards,
    Michael
    Mike,

    Replace works fine for me also ... Yaeh, the backslash was a bad idea ...

    Cathy: Try recompiling your app and look to see if there are any invaid or missing references ...

  6. #6
    Join Date
    Jan 2004
    Location
    TX, USA
    Posts
    347

    Re: Replace Chr(32) or "*" with ""

    I can make REPLACE work outside of this program.
    I even have a lot of Replaces elsewhere in the code but
    it just doesn't want to work at the place I have it.
    ????
    Cathy
    Jan 2004 - NEWBIE to VB6
    Any and all help appreciated

  7. #7
    Join Date
    Jan 2004
    Location
    TX, USA
    Posts
    347

    Re: Replace Chr(32) or "*" with ""

    I think I have found the problem but not exactly sure.
    My replace was inside a WHILE statement and it affected
    it somehow or another.
    Thanks guys...
    Cathy
    Jan 2004 - NEWBIE to VB6
    Any and all help appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured