Results 1 to 8 of 8

Thread: removing 2 numbers from a string........

  1. #1

    Thread Starter
    Addicted Member Smie's Avatar
    Join Date
    Jun 1999
    Location
    Columbus, OH
    Posts
    249

    Question

    how would i go about removing the number '43' from a string? eg......



    'Hello my na43me is bob'


    i want to search the string and remove the number


    thanks much!

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    This will do it:[code]Dim sOldStr As String
    Dim sNewStr As String

    sOldStr = "Hello my na43me is bob" 'could replace this with sOldStr = Trim(Text1) where text1 has the string
    sNewStr = Replace(sOldStr, "43", "")
    MsgBox sNewStr
    Wade

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Here's a more general approach to the problem that will remove ANY digits from a string (I don't know if you need this, but at the risk of overkill here goes):

    Code:
    Dim strOrigString As String
    Dim strNewString As String
    Dim strCurrChar As String
    Dim intX As Integer
    Dim intLen As Integer
    
    ' assume strOrigString contains "A1B2C3D4E5"
    intLen = Len(strOrigString)
    strNewString = ""
    For intX = 1 To intLen
        strCurrChar = Mid$(strOrigString, intX, 1)
        If Instr("0123456789", strCurrChar) = 0 Then
            strNewString = strNewString & strCurrChar
        End If
    Next
    ' strNewString should now be "ABCDE"
    "It's cold gin time again ..."

    Check out my website here.

  4. #4
    Member
    Join Date
    Aug 2000
    Location
    London, ON
    Posts
    40

    Post Try this...

    private function NoNum (YourString as String) as String
    dim Temp as String
    dim i as Integer
    For i = 1 to len (YourString)
    If IsNumeric (mid (YourString, i, 1)) = False then
    Temp$ = Temp$ & mid (YourString, i, 1)
    EndIf
    Next i
    NoNum = Temp$
    EndSub

    PS use type declaration characters so later you can remember what the datatype was.
    Visual Basic 6 Professional Edition
    Captain Pinko

    also:
    Turbo Pascal, Turing, QBasic

  5. #5
    Member
    Join Date
    Aug 2000
    Location
    London, ON
    Posts
    40

    Unhappy Sorry abut the code...

    it seems to have removed my spaces, causing my code to go retarded, I did format itnicely but that got undone, sorry again...
    Visual Basic 6 Professional Edition
    Captain Pinko

    also:
    Turbo Pascal, Turing, QBasic

  6. #6
    Guest
    type-declaration-characters make the code look confusing,
    and I usually specify the type of variables in the name...

    Code:
    Dim strMyVar As String
    Dim intMyVar As Integer
    Dim lngMyVar As Long
    Dim dblMyVar As Double
    Dim sglMyVar As Single
    Dim ccyMyVar As Currency
    Dim blnMyVar As Boolean
    Dim vntMyVar As Variant
    Dim paPoint As POINTAPI
    Its called Hungarian Notation

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For more information on Hungarian Notation, go here: http://forums.vb-world.net/showthrea...4363#post93187
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Captain Pinko

    If you want your code to look formatted enclose it in Coade tags

    write something like this
    [code@]
    Dim a As Integer 'There are lots of spaces before this comment
    [/code@]

    but remove the @ characters and it comes out like this

    Code:
    Dim a As Integer     'There are lots of spaces before this comment

    check Here for other tags

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