stripping a string - Newbie
Author Message
stripping a string - Newbie

how do I strip the numbers out of a string
EG:  string = "5 cards" or "play 5 games"
I just want the number 5

ST

Sat, 28 Jun 2003 14:42:46 GMT
stripping a string - Newbie
left\$(varible, 1)

Sat, 28 Jun 2003 17:25:24 GMT
stripping a string - Newbie

Quote:

> how do I strip the numbers out of a string
> EG:  string = "5 cards" or "play 5 games"
> I just want the number 5

> ST

Hi.

Val()  function recognizes the number in the string first positions, so
use:

C = Val("5 cards")

If you have a string beginning with a word, split the string and chack
each member:

dim S() as string, ss as variant, v as integer

S = split(STR, " ")
for each ss in S
if IsNumeric(ss) then
v =  cint(ss)
end if
next ss

HTH,
Yaniv.

Sat, 28 Jun 2003 20:29:16 GMT
stripping a string - Newbie
Here's a start for you:
Put a command button on a new form.
Private Sub Command1_Click()
Dim x As String, i As Long
Dim z As String, test As String
x = " 2 play 5 games 18"
z = vbNullString
For i = 1 To Len(x)
test = Mid\$(x, i, 1)
If IsNumeric(test) Then
z = z & test
End If
Next i
MsgBox "I found " & z
End Sub

You can play with various ways of doing it.
HTH
Gary

Quote:
> how do I strip the numbers out of a string
> EG:  string = "5 cards" or "play 5 games"
> I just want the number 5

> ST

Sat, 28 Jun 2003 23:11:23 GMT
stripping a string - Newbie
Get all digits in a string.

dim i as integer, j as integer, str as string
for i=1 to len(str)
j=Asc(Mid(str,i,1))
if j <58 and j>47 then
numeric
else
not
end if
next i

Quote:

> how do I strip the numbers out of a string
> EG:  string = "5 cards" or "play 5 games"
> I just want the number 5