Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RemoveSingleCharacterFromString

    I tried this:

    string to to manipulated: "this is a test"
    character to remove: "i"

    result: "this is a test"

    Hummmm. What exactly is this supposed to do?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    It will return the string, in the case of your example "ths s a test" to the function name.

    In other words, try this:

    <pre>Sub TestRemove
    MsgBox gstrRemoveSingleCharacterFromString("this is a test", "i")
    end Sub</pre>


  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RemoveSingleCharacterFromString

    That's zactly what I tried. Sumpin' ain't woikin' rat.

    I just copied and pasted your code. Check it again.

    Hint: nothing happens to the string unless it starts with a verticaltab.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: RemoveSingleCharacterFromString

    Only if you change vbVerticalTab to vstrCharacterToBeRemoved I think.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    The original post and the text file have been update.

    The problem was that my use of it was with a vbVerticalTab. Therefore, when I made it "generic" it still worked for me. Thanks for pointing this out.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RemoveSingleCharacterFromString

    You're welcome.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    Thanks

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: RemoveSingleCharacterFromString

    I'm a newby who recently wrote something similar for Office97 so I'll take a careful look at your code. FWIW, I wanted a function that would strip any number of parameter characters out. Here 'tis, kind suggestions welcome:

    Public Function StripTheseChars(strInput As String, strChars2Del As String) As String
    Dim lngPos As Long, lngInputSLen As Long, lngDelCharsLen As Long, lngCounter As Long
    Dim strCurrentChar2Del As String
    lngDelCharsLen = Len(strChars2Del)
    For lngCounter = 1 To lngDelCharsLen
    strCurrentChar2Del = Mid(strChars2Del, lngCounter, 1)
    Do While InStr(strInput, strCurrentChar2Del)
    lngInputSLen = Len(strInput)
    lngPos = InStr(strInput, strCurrentChar2Del)
    strInput = Left(strInput, lngPos - 1) & Right(strInput, lngInputSLen - lngPos)
    Loop
    Next lngCounter
    StripTheseChars = strInput
    End Function

    It should take arguments in the form:

    Sub showstrip()
    MsgBox StripTheseChars("When [in] Rome (or perhaps Italy), do as the *(&%&** {Romans}", " .*,<>|/()[]{}""")
    End Sub

    (double quote "" will strip quote characters)

    ... be nice, I was proud of myself to just get this working. Things like this are the reason I made my plea for a code warehouse.
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RemoveSingleCharacterFromString

    This works too.

    ' This function removes a character from the text
    ' Written by Rupert email ath@hotware.co.uk

    Public Function removeChr(StrRemoveChr As String, StrToRemove As String)

    Let removeChr = Replace(StrRemoveChr, StrToRemove, "", 1, -1, 1)

    End Function

  10. #10
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RemoveSingleCharacterFromString

    Try this test and see what you get:

    <pre> msgbox (gstrRemoveSingleCharacterFromString("Thiis iis a striing", "i")}
    </pre>


    Changing The For statement to the below will fix that problem:

    <pre> For intCounter = Len(vstrStringToBeManipulated) To 1 Step -1
    </pre>

    Legare Coleman

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: RemoveSingleCharacterFromString

    Good one, Rupert. I was catching up on this thread and thinking Replace function too. But no use to the 97 VBA'ers.

  12. #12
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    Yes, I forgot about the reverse stepping. Gotta remember that. [img]/forums/images/smilies/smile.gif[/img]

  13. #13
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    Yes, this code was written to be used at work, Word 97.

  14. #14
    kelliel
    Guest

    RemoveSingleCharacterFromString

    <P ID="del"><FONT SIZE=-1>Post deleted by kelliel</FONT>

  15. #15
    kelliel
    Guest

    Re: RemoveSingleCharacterFromString

    As Legare Coleman pointed out, your For/Next loop should move backwards through the string instead of forwards. I, too, had that problem in the code I posted.

Page 1 of 2 12 LastLast

Posting Permissions

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