|
-
Feb 19th, 2009, 11:01 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Detect a string formatting
Hi, i have been using the InStr function to detect strings within strings...
if instr(1, "Call", Line) then...
but i have a string it needs to detect, but i need to detect it by the formatting of it, as every letter in the string will be different meaning i cannot use the InStr function.
the text will appear like this:
7h 9d Kh (Flop)
OR
2c 4d Qh Qs (Turn)
OR
Th 3d 4h 9s Jc (River)
the first letter will always be a number or: J,Q,K,A
and the second letter will always be lowercase: c,h,d,s
Thanks for all your help here!
I will do my best to add you to the credits of my new apps.
-
Feb 19th, 2009, 11:29 PM
#2
Re: Detect a string formatting
Because each 'word' you use, have a space between them, you can simply Split() up the content, that you can analyse element by element.
Code:
Dim aLine() As String, i as Long
aLine = Split(Line," ")
For i = 0 to Ubound(aLine)
Select Case uCase(Left$(aLine(i),1))
Case Is = "J"
'J...
Debug.Print Right$(aLine(i),1) 'secondary letter.
Case Is = "Q"
'Q...
'...... more cases come here
Case Is = "1"
'1...
Case Is = "2"
'2...
'...... even more cases come here
Case Else
'Nothing the above, it could be an illegal message.
End Select
Next i
-
Feb 19th, 2009, 11:38 PM
#3
Thread Starter
Addicted Member
Re: Detect a string formatting
Here is an example of the text it will come across:
Dealer: ronnieone calls 10
Dealer: willeone5 calls 5
Dealer: jfranck checks
Dealer:
Dealing Flop
5s 9d 7h
Dealer: willeone5 checks
Dealer: jfranck checks
Dealer: Lolitorico27 bets 10
Dealer: pomca folds
Dealer: setport77 calls 10
Dealer: retxinesss calls 10
Dealer: yoris14 folds
Dealer: jovenard folds
Dealer: ronnieone folds
Dealer: willeone5 calls 10
Dealer: jfranck folds
Dealer:
Dealing Turn
5s 9d 7h Ad
Dealer: willeone5 checks
Dealer: Lolitorico27 bets 20
I can detect the "Dealing Flop", and "Dealing Turn". but it needs to be able to get the cards also, as they will be split up, and then put into seperate text boxes.. and then images
i was expecting somthing like: if Format(line, "## ## ##") then flop
Thanks for all your help here!
I will do my best to add you to the credits of my new apps.
-
Feb 19th, 2009, 11:45 PM
#4
Re: Detect a string formatting
Before each 'data words', there is a Command, that you have to interpret, that the next line will be a Turn, a Flop or whatever it is. Store the result in a value (lNextData) that you can recall next time.
Code:
Private lNextData As Long
'....
lNextData = 0 'Clear the value
If Instr(Line,"Dealing Flop") > 0 Then lNextData = 1
If Instr(Line,"Dealing Turn") > 0 Then lNextData = 2
If Instr(Line,"Dealing River") > 0 Then lNextData = 3
Now, where you process the lines, you can simply check the lNextData, if its greater than zero, it should be interpreted, otherwise your code have to skip the extra process.
Code:
Dim aLine() As String, i as Long
If lNextData = 1 Then
'Process the Flop event
aLine = Split(Line," ")
For i = 0 to Ubound(aLine)
'...
ElseIf lNextData = 2 Then
'Process the Turn event
aLine = Split(Line," ")
For i = 0 to Ubound(aLine)
'...
ElseIf lNextData = 3 Then
'Process the River event
Else
'It is not a data word, you can process those lines here...
lNextData = 0 'Clear the value
If Instr(Line,"Dealing Flop") > 0 Then lNextData = 1
If Instr(Line,"Dealing Turn") > 0 Then lNextData = 2
If Instr(Line,"Dealing River") > 0 Then lNextData = 3
End If
-
Feb 19th, 2009, 11:50 PM
#5
Re: Detect a string formatting
Try this one
vb Code:
Private Sub Command1_Click() MsgBox (TestRegExp(Text1.Text)) End Sub Function TestRegExp(myString As String) 'Create objects. 'the first letter will always be a number or: J,Q,K,A 'and the second letter will always be lowercase: c,h,d,s Dim objRegExp As RegExp Dim objMatch As Match Dim colMatches As MatchCollection Dim RetStr As String ' Create a regular expression object. Set objRegExp = New RegExp 'Set the pattern by using the Pattern property. objRegExp.Pattern = "([0-9]|[JQKA])[chds]+" ' Set Case Insensitivity. objRegExp.IgnoreCase = True 'Set global applicability. objRegExp.Global = True 'Test whether the String can be compared. If (objRegExp.Test(myString) = True) Then 'Get the matches. Set colMatches = objRegExp.Execute(myString) ' Execute search. For Each objMatch In colMatches ' Iterate Matches collection. RetStr = RetStr & "Match found at position " RetStr = RetStr & objMatch.FirstIndex & ". Match Value is '" RetStr = RetStr & objMatch.Value & "'." & vbCrLf Next Else RetStr = "String Matching Failed" End If TestRegExp = RetStr End Function
Add reference to : Microsoft VBScript Regular Expressions 5.5,
Please mark you thread resolved using the Thread Tools as shown
-
Feb 19th, 2009, 11:51 PM
#6
Thread Starter
Addicted Member
Re: Detect a string formatting
this method just came to me, thanks for writing that up once again.
Thanks for all your help here!
I will do my best to add you to the credits of my new apps.
-
Feb 19th, 2009, 11:53 PM
#7
Re: [RESOLVED] Detect a string formatting
@danasegarane: Nice! RegExp, i just can learn its syntax ^^
-
Feb 20th, 2009, 12:00 AM
#8
Re: [RESOLVED] Detect a string formatting
Please mark you thread resolved using the Thread Tools as shown
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
|