Emile Schwarz
2003-12-25 13:22:40 UTC
Hi all,
This returns every digits that are neightbors:
rg.SearchPattern = "[0-9].*"
but how can I extract the digits from a multi-characters strings ?
ex: get "12" from "a12", "1a2", "12a" and so on.
This is for a typing error free: it happens sometimes that I (the user) type
some characters inside a number; that's the reason why I used "a12" (and other
variations) as the example.
The following (a and b) lines seems to give the same result:
a. rg.SearchPattern = "[\d].*"
b. rg.SearchPattern = "[0-9].*"
returns "12" for "a12" and "12a", but "1a2" fails.
The GetNumber function works fine (in another project *) because all digits are
together. But I need to get extract all digits from a string; this string
usually must have only 2 two 4 digits, but a typical user sometimes can make
typos (add a character by error).
TIA,
Emile
The code above comes from the following function:
Function GetNumber(source As String) As String
//
// Name: GetNumber
// Inputs: source As String
// Outputs: String
// Syntax: String = GetNumber(source)
// Created: 19-12-2003; 13:20
// Creator: Emile Schwarz (emile.schwarz-***@public.gmane.org)
//
// Based on the RegEx Class example
//
Dim rg As RegEx
Dim myMatch As RegExMatch
rg = New RegEx
rg.SearchPattern = "[0-9].*"
// "[\d].*" // Returns all digits
// "[0-9].*" // Returns all digits too !
myMatch = rg.search(source)
if myMatch = Nil Then
Return ""
Else
Return myMatch.SubExpressionString(0)
End if
Exception err As RegExException
MsgBox err.message
End Function
Nota: to change this function from GetNumber to GetText, replace the
.SearchPattern to:
// Returns all the alphabetic characters from the start of the string
rg.SearchPattern = ".*[a-z]"
* that project scan and process strong typed text informations where the atom(s)
can are alphabetic information sometimes followed by a numeric number (no mix-up
between alphabetic and numeric characters).
- - -
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
This returns every digits that are neightbors:
rg.SearchPattern = "[0-9].*"
but how can I extract the digits from a multi-characters strings ?
ex: get "12" from "a12", "1a2", "12a" and so on.
This is for a typing error free: it happens sometimes that I (the user) type
some characters inside a number; that's the reason why I used "a12" (and other
variations) as the example.
The following (a and b) lines seems to give the same result:
a. rg.SearchPattern = "[\d].*"
b. rg.SearchPattern = "[0-9].*"
returns "12" for "a12" and "12a", but "1a2" fails.
The GetNumber function works fine (in another project *) because all digits are
together. But I need to get extract all digits from a string; this string
usually must have only 2 two 4 digits, but a typical user sometimes can make
typos (add a character by error).
TIA,
Emile
The code above comes from the following function:
Function GetNumber(source As String) As String
//
// Name: GetNumber
// Inputs: source As String
// Outputs: String
// Syntax: String = GetNumber(source)
// Created: 19-12-2003; 13:20
// Creator: Emile Schwarz (emile.schwarz-***@public.gmane.org)
//
// Based on the RegEx Class example
//
Dim rg As RegEx
Dim myMatch As RegExMatch
rg = New RegEx
rg.SearchPattern = "[0-9].*"
// "[\d].*" // Returns all digits
// "[0-9].*" // Returns all digits too !
myMatch = rg.search(source)
if myMatch = Nil Then
Return ""
Else
Return myMatch.SubExpressionString(0)
End if
Exception err As RegExException
MsgBox err.message
End Function
Nota: to change this function from GetNumber to GetText, replace the
.SearchPattern to:
// Returns all the alphabetic characters from the start of the string
rg.SearchPattern = ".*[a-z]"
* that project scan and process strong typed text informations where the atom(s)
can are alphabetic information sometimes followed by a numeric number (no mix-up
between alphabetic and numeric characters).
- - -
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>