|
-
May 7th, 2001, 03:07 AM
#1
Thread Starter
Lively Member
String Variable
I know that the 1st character of a unknown string variable is a number & the following characters are also numbers but do not know exactly how many following characters are numbers, so how can i exact only numbers from this string starting from the 1st character?
-
May 7th, 2001, 12:34 PM
#2
IF the string came from c it will be null-terminated - chr(0) is the last character.
If you are using a byte array the last char is Ubound(arr() )
IF you are staying in VB, then pass a dynamic string ByVal into the sub/function. VB code gives len(str).
-
May 9th, 2001, 01:09 AM
#3
It seems to me that you have a string that starts with numerals and continues for however long and becomes letters or something.
This is a quote from the help file on the val keyword
The Val function stops reading the string at the first character it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized. However, the function recognizes the radix prefixes &O (for octal) and &H (for hexadecimal). Blanks, tabs, and linefeed characters are stripped from the argument.
The following returns the value 1615198:
Val(" 1615 198th Street N.E.")
-
May 9th, 2001, 12:39 PM
#4
Use this function
Code:
Function GetNumCount(ByVal sString As String) As Long
For i = 1 To Len(sString)
If Mid(sString, i, 1) Like "#" Then GetNumCount = GetNumCount + 1
Next i
End Function
Usage:
Code:
Print GetNumCount("kjgd8732jfdsk8343jf3")
-
May 9th, 2001, 12:45 PM
#5
Interesting - I didn't get what he wanted - I thought he wanted the length of the string so he could search it. Duh.
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
|