Sign in to follow this  
Followers 0
tom13

How to get XX from a string?

7 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm working on a poker bot and have a string that looks like this:

nbgolferguy: yw 
nbgolferguy: mate 
frp40: welll sid is ok 
Dealer: ** Dealing Flop ** [ 4d, 9h, 2h ] 
nbgolferguy: yes he is 
frp40: no k woohoo 
nbgolferguy: wooooooooohooooooooo 
Dealer: ** Dealing Turn ** [ 6h ] 
frp40: lol 
nbgolferguy: WOOOOOOOOHOOOOOOO 
Dealer: sidmichael does not show cards. 
#55187107513: sidmichael wins 34.304,57 play chips 
Dealer: Game #55187111342 starts. 
nbgolferguy: vnh 
frp40: gh woo hoo 
Dealer: ** Dealing down cards ** 
frp40: hey sis what time is it there 
Dealer: ** Dealing Flop ** [ 6d, 6c, Td ] 
frp40: sid 
nbgolferguy: 7 pm 
sidmichael: 8 am 
frp40: saturday 
Dealer: ** Dealing Turn ** [ Ah ] 
nbgolferguy: sunday 
sidmichael: sunday 
frp40: doesnt tske much to confuse me k 
nbgolferguy: they're like a XXXX day ahead of us 
Dealer: ** Dealing River ** [ 2d ] 
nbgolferguy: f u l l 
Dealer: ForTheGlory1 has left the table.

Now I need to get the [ xy, xy, xy ] from the last Dealer: ** Dealing Flop ** [ xy, xy, xy ]

Then I want the first one to become $card1, second one $card2 and third one $card3

So with my example $card 1 should be 6d, $card2 should be 6c and $card3 should be Td

I tried things like Stringsplit but could not get it working...

Any help is appreciated, thanks in advance :whistle:

Edited by tom13

Share this post


Link to post
Share on other sites



If your string is $s

the position of the last Dealer is

$lastdealer = StringinStr($s,"Dealer",0,-1)

so we could take the end of the string

$lastbit = stringRight($s,stringlen($s) - $lastdealer)

Now look for the '[' and the ']'

$brachetL = stringinStr($lastbit,'[')

$bracketR = StringinStr($lastbit,']')

(I'm making this up as i go along so don't take it as read!)

Bit between the brackets is

$vals = StringMid($lastbit,$barcketL + 1, $bracketR - $bracketL - 1)

$Result = stringsplit($vals,',')

Now $Result is an array with your values in it. (Maybe)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

$TestString = 'nbgolferguy: yw' & @CRLF & _
'nbgolferguy: mate' & @CRLF & _
'frp40: welll sid is ok' & @CRLF & _
'Dealer: ** Dealing Flop ** [ 4d, 9h, 2h ]' & @CRLF & _
'nbgolferguy: yes he is' & @CRLF & _
'frp40: no k woohoo' & @CRLF & _
'nbgolferguy: wooooooooohooooooooo' & @CRLF & _
'Dealer: ** Dealing Turn ** [ 6h ]' & @CRLF & _
'frp40: lol' & @CRLF & _
'nbgolferguy: WOOOOOOOOHOOOOOOO' & @CRLF & _
'Dealer: sidmichael does not show cards.' & @CRLF & _
'#55187107513: sidmichael wins 34.304,57 play chips' & @CRLF & _
'Dealer: Game #55187111342 starts.' & @CRLF & _
'nbgolferguy: vnh' & @CRLF & _
'frp40: gh woo hoo' & @CRLF & _
'Dealer: ** Dealing down cards **' & @CRLF & _
'frp40: hey sis what time is it there' & @CRLF & _
'Dealer: ** Dealing Flop ** [ 6d, 6c, Td ]' & @CRLF & _
'frp40: sid' & @CRLF & _
'nbgolferguy: 7 pm' & @CRLF & _
'sidmichael: 8 am' & @CRLF & _
'frp40: saturday' & @CRLF & _
'Dealer: ** Dealing Turn ** [ Ah ]' & @CRLF & _
'nbgolferguy: sunday' & @CRLF & _
'sidmichael: sunday' & @CRLF & _
'frp40: doesnt tske much to confuse me k' & @CRLF & _
'nbgolferguy: they''re like a XXXX day ahead of us' & @CRLF & _
'Dealer: ** Dealing River ** [ 2d ]' & @CRLF & _
'nbgolferguy: f u l l' & @CRLF & _
'Dealer: ForTheGlory1 has left the table.'

MsgBox(0, "", GetLastFlop($TestString) )

Func GetLastFlop($sString)
    $sRegExp = StringRegExp($sString,"Dealer: \*\* Dealing Flop \*\* \[ .., .., .. \]",3)
    If @error Then Return SetError(1,0,0)
    Return StringTrimRight(StringTrimLeft($sRegExp[UBound($sRegExp)-1],29),1)
EndFunc

Share this post


Link to post
Share on other sites

#include<Array.au3>
$sStr = ClipGet()

$aMatch = StringRegExp($sStr, "Dealer: \*\* Dealing Flop \*\* \[ (.{2}), (.{2}), (.{2}) \]", 3)
Local $aData[3]
If not @error Then ;found match
    Local $iTemp = 0
    For $i = UBound($aMatch)-3 to UBound($aMatch)-1
        $aData[$iTemp] = $aMatch[$i]
        $iTemp += 1
    Next
EndIf
_ArrayDisplay($aData)

This will work if data is formatted the same way your example is. Copy the following to clipboard before running my script

nbgolferguy: yw 
nbgolferguy: mate 
frp40: welll sid is ok 
Dealer: ** Dealing Flop ** [ 4d, 9h, 2h ] 
nbgolferguy: yes he is 
frp40: no k woohoo 
nbgolferguy: wooooooooohooooooooo 
Dealer: ** Dealing Turn ** [ 6h ] 
frp40: lol 
nbgolferguy: WOOOOOOOOHOOOOOOO 
Dealer: sidmichael does not show cards. 
#55187107513: sidmichael wins 34.304,57 play chips 
Dealer: Game #55187111342 starts. 
nbgolferguy: vnh 
frp40: gh woo hoo 
Dealer: ** Dealing down cards ** 
frp40: hey sis what time is it there 
Dealer: ** Dealing Flop ** [ 6d, 6c, Td ] 
frp40: sid 
nbgolferguy: 7 pm 
sidmichael: 8 am 
frp40: saturday 
Dealer: ** Dealing Turn ** [ Ah ] 
nbgolferguy: sunday 
sidmichael: sunday 
frp40: doesnt tske much to confuse me k 
nbgolferguy: they're like a XXXX day ahead of us 
Dealer: ** Dealing River ** [ 2d ] 
nbgolferguy: f u l l 
Dealer: ForTheGlory1 has left the table.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

Hey, all your solutions were really interesting.. thanks for your help :whistle:

Share this post


Link to post
Share on other sites

hey again, this might sound stupid but I have to do the same with a second string but can't figure it out myself :/ I think it's because I now only need 1 variable so there is no array, and I'm not very good with arrays :whistle:

I now need to get xx from the following line in my example above:

Dealer: ** Dealing Turn ** [ xx ]

So with my example above it should give "Ah"

Anyone can help me out?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0