Results 1 to 8 of 8

Thread: Remove "'"

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Remove "'"

    I have tried the following:

    Initial value = 5'

    Code:
                                    If strValue.Contains(Chr(39)) Then
                                        strValue = strValue.Replace(Asc(39), "").Trim
    
                                    End If
    
    
                                    If strValue.Contains(Asc(39)) Then
                                        strValue = strValue.Replace(Chr(39), "").Trim
    
                                    End If
    
    
                                    If strValue.Contains("'") Then
                                        strValue = strValue.Replace("'", "").Trim
    
                                    End If
    I'm assuming the difficulty is that there is already a ' somewhere in the interpretation, since it is a string.

    Thanks!
    Last edited by ssabc; May 3rd, 2019 at 08:14 AM.

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Remove "'"

    So, what is the issue? Is it not removing the apostrophe / single quote? Are you sure that the character in your actual string is really an ASCII 39 value? There are other similar characters with different ASCII values.

  3. #3
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Remove "'"

    you could do
    Code:
            Dim str As String = "this is a '"
            If str.Contains("'") Then
                str = str.Replace("'"c, "")
            End If
    or
    Code:
            Dim str As String = "this is a '"
            If str.Contains("'") Then
                str = str.Replace("'", "")
            End If
    Why are you removing it? Is it by chance you are trying to insert/update this value in a database?

  4. #4
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Remove "'"

    Asc() is to get the code from a chr ... I think you mean Chr(), this gets the chr from the code...

    You should turn Option Strict On and you would realize this...

    Also you should not check against one thing and then use another to replace ... just use "'" to replace if you are using "'" to check.

    Kris

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: Remove "'"

    The value is simply text. If the variable contains a "'", I want to get rid of it. It resides in a data grid view, manually created, no data binding...

  6. #6
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Remove "'"

    Please show where StrValue gets it's initial value.

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Remove "'"

    I wonder if it's really a ` and not a '

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Remove "'"

    His OP uses ' for checking, either we are getting trolled or there is something else wrong, such as the input to the strValue isnt what he expects it to be.

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