Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665

    Unanswered: Remove a Character From a String

    I need to remove a ' from a string of names. Any suggestion?
    Jim

  2. #2
    Join Date
    Dec 2002
    Posts
    5
    Hi You can use the Mid (pl see the syntax in the help) Function to
    remove or substitute any new characters in the string.

    If you can tell what exactly you are trying to do, I can explain in detail

  3. #3
    Join Date
    Nov 2002
    Posts
    150
    Originally posted by praveenp
    Hi You can use the Mid (pl see the syntax in the help) Function to
    remove or substitute any new characters in the string.

    If you can tell what exactly you are trying to do, I can explain in detail
    I don't think Mid will strip a ' from a string. Here is some debug output:

    x="123"
    mid(x,2,1)="Z"
    ?x
    1Z3
    x="123"
    mid(x,2,1)=""
    ?x
    123

    You could also use Instr to find the ' and some math using Len to strip off the before and after.

  4. #4
    Join Date
    Dec 2002
    Posts
    5
    Hi,
    Instead of "" if you substitute with chr(32) it strips,
    that is in your example it will displayed as 1 3 (with space between 1 and 3)
    but ofcourse as you said if you want to join these two again,
    you have to use instr, len and mid function depending on your need.

    Praveen.

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    You can use the replace function to remove the apostrophe or to add an additional apostrophe if you are trying to keep the single quote in the database.

  6. #6
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    Originally posted by rnealejr
    You can use the replace function to remove the apostrophe or to add an additional apostrophe if you are trying to keep the single quote in the database.
    This replace function.....will it work dynamicaly, you see i dont know where in the string the ' will be it is up to the end use and the selection that he makes. Can you give me more info on replace?
    Jim

  7. #7
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    what about something like this?


    Public Function ReplaceString(InputString As String, ReplaceThisChar As String, WithThisChar As String) As String

    ReplaceThisChar = Left(Trim(ReplaceThisChar), 1)
    WithThisChar = Left(Trim(WithThisChar), 1)

    ' you can use do while and INSTR fce - it can be faster....
    For i = 1 To Len(InputString)
    If Mid(InputString, i, 1) = ReplaceThisChar Then
    InputString = Left(InputString, i - 1) & WithThisChar & Mid(InputString, i + 1)
    End If
    Next

    ReplaceString = InputString
    End Function


    then you can try

    ? ReplaceString ("Hi 'this' is me","'","")
    ? ReplaceString ("Hi 'this' is me","'",chr(34))
    ...



    jiri

  8. #8
    Join Date
    Feb 2002
    Posts
    2,232
    Dim strString as string

    strString = "This o'ld house"

    strString = replace(strString,"'","")

    msgbox strString

  9. #9
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    Originally posted by rnealejr
    Dim strString as string

    strString = "This o'ld house"

    strString = replace(strString,"'","")

    msgbox strString
    Cool man!! thats exactly what I needed
    thanx
    Jim

  10. #10
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    some of us use still Access97 ..... :-(

    replace works in Access2k only


    jiri

  11. #11
    Join Date
    Feb 2002
    Posts
    2,232
    Jim - Happy to help.

  12. #12
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    Originally posted by playernovis
    some of us use still Access97 ..... :-(

    replace works in Access2k only


    jiri
    Sorry man....I still use 97 but any new development goes into win2k at my office.
    thanx for the help though
    Jim

  13. #13
    Join Date
    Jan 2003
    Location
    UK
    Posts
    5
    The enclosed function works with 97.

    Caters for multiple characters & multiple instances of the same void character.

    '****code start****
    Public Function StripOutVoidCharacters(varstring As String) As String

    Dim varchar As String, i As Long, finalstring As String

    For i = 1 To Len(varstring)
    varchar = Mid(varstring, i, 1)
    Select Case varchar
    Case "'", "?", "/", "!", "%"
    Case Else
    finalstring = finalstring & varchar
    End Select
    Next i

    StripOutVoidCharacters = finalstring

    End Function
    '****code end****

    to call the procedure use

    strname = StripOutVoidCharacters (strname)

Posting Permissions

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