|
-
Aug 18th, 2000, 04:01 PM
#1
Thread Starter
Addicted Member
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!
-
Aug 18th, 2000, 04:08 PM
#2
Hyperactive Member
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
-
Aug 18th, 2000, 05:03 PM
#3
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.
-
Aug 18th, 2000, 08:54 PM
#4
Member
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
-
Aug 18th, 2000, 08:56 PM
#5
Member
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
-
Aug 18th, 2000, 10:58 PM
#6
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
-
Aug 19th, 2000, 08:13 AM
#7
Monday Morning Lunatic
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
-
Aug 19th, 2000, 09:11 AM
#8
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|