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

Thanks in advance
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

> Thanks in advance
> 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.
Add this event code:
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

> Thanks in advance
> 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

> Thanks in advance
> ST



Sat, 28 Jun 2003 22:04:30 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Pls Help Newbie: Stripping Strings of CR and LF

2. Help Newbie - String stripping...?

3. Newbie: stripping carriage returns from a string

4. Strip attachment off Email (Sorry newbie)

5. Newbie: How to select a tab on a tab strip

6. Tab Strip help needed, Newbie?

7. newbie: strip the carriage returns from a text file

8. NEWBIE:Function to strip off unwanted characters

9. Strip Spaces from string

10. Stripping vbCrLf from strings

11. Strip spaces from string

12. String.Trim does not strip

 

 
Powered by phpBB® Forum Software