Hi,
I have a string in a text box (text1.text = “chapter-12/heading-321/verse-41”).
I want to extract the values of chapter, heading and verse as 12,321 and 41 respectively.
Kindly help.
Thanks and regards,
Umar
Printable View
Hi,
I have a string in a text box (text1.text = “chapter-12/heading-321/verse-41”).
I want to extract the values of chapter, heading and verse as 12,321 and 41 respectively.
Kindly help.
Thanks and regards,
Umar
This my way of getting the numbers :)
Code:Option Explicit
Private Sub Command1_Click()
'Mark A Reference to Microsoft VBScript Regular Expression 5.5 Library
On Error GoTo Err1
Dim regx As New RegExp
Dim m As Match 'to get the eatch match
Dim mc As MatchCollection 'Contains the match collections
Dim spattern As String
regx.Pattern = ("[0-9]+") 'Pattern to get the numerbers only
regx.Global = True 'Search for global in the text
If regx.Test(Text1.Text) = False Then MsgBox "No Matches": Exit Sub 'If no matches found then exit sub
Set mc = regx.Execute(Text1.Text) 'Execute
Debug.Print mc.Count 'no of occurance
For Each m In mc 'Loop through each occurance and pring
Debug.Print m.Value 'print the number values
Next
Exit Sub
Err1:
MsgBox Err.Description
Exit Sub
End Sub
Something like this would work:
Code:sub Form1_Load()
dim s as integer
dim arr() as string
text1.text = “12/321/41”
arr()=split(text1.text,"/")
debug.print arr(0)
debug.print arr(1)
debug.print arr(2)
End Sub
try this,
I hope it's useful
Code:option explicit
Sub test()
Dim d() As String
Dim s As Variant
d = Split(Text1.Text, "/")
For Each s In d
Debug.Print Right(s, InStr(StrReverse(s), "-") - 1)
Next
End Sub
what about following:
[CODE]
text1.text = "chapter-1/rukoo-1/verse-1"
chlen = InStr(Text1.Text, "/rukoo") - (InStr(Text1.Text, "chapter-") + 8)
rklen = InStr(Text1.Text, "/verse") - (InStr(Text1.Text, "rukoo-") + 6)
vrlen = InStr(Text1.Text, "verse-") + 6
ch = Mid(Text1.Text, 9, chlen)
rk = Mid(Text1.Text, Len(ch) + 16, rklen)
vr = Mid(Text1.Text, Len(ch) + Len(rk) + 23, vrlen)
[\CODE]
Above code solves my problem
Umar
Hello,
as everyone is showing a method,
here comes mine, then !
Code:Private Sub Command1_Click()
toto = "chapter-12/heading-321/verse-41"
For i = 1 To Len(toto)
If IsNumeric(Mid(toto, i, 1)) Then
titi = titi & Mid(toto, i, 1)
Else
If titi <> "" And Right(titi, 3) <> " - " Then titi = titi & " - "
End If
Next
MsgBox titi
End Sub
and a little bit faster one, just for fun ...
Code:Private Sub Command1_Click()
toto = "chapter-12/heading-321/verse-41"
While toto <> ""
If IsNumeric(Mid(toto, 1, 1)) Then
titi = titi & Val(toto) & " - "
toto = Mid(toto, 1 + Len(Str(Val(toto))))
Else
toto = Mid(toto, 2)
End If
Wend
MsgBox titi
End Sub