mikehunt114 Posted October 24, 2006 Share Posted October 24, 2006 I'm looking to get a value from the following string: $string = "Blah Blah Blah increased! (Now at 10%)" I want to grab that number 10 and put it in a variable. The number increases and so is different every time I want to grab it. I can't trim this string. Is there some way to grab just that number before the %? IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 I just checked to make sure I had the latest beta and I don't see a _StringBetween... IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 24, 2006 Share Posted October 24, 2006 (edited) Ok, I see a pattern...does it always say "(Now At xx%)"? And is "xx" always a number? And is it the ONLY number in that pattern? If so, then $string = "Blah Blah Blah increased! (Now at 10%)" $temp = StringInStr($string, "(Now at") $temp = StringMid($string, $temp, 30) $temp = StringSplit($temp, "") If IsArray($temp) Then $NewString = "" For $x = 1 To $temp[0] If IsNumber($temp[$x]) Then $NewString = $NewString & $temp[$x] Next EndIf MsgBox(0,"",$NewString) Edited October 24, 2006 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 There are other numbers in the input. =/ IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 24, 2006 Share Posted October 24, 2006 There are other numbers in the input. =/You didn't say that before.Give an entire string please as it would be grabbed?Or you can adjust the length of the count in StringMid() ... I just chose 30 characters as arbitrary. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 (edited) You didn't say that before.Give an entire string please as it would be grabbed?Or you can adjust the length of the count in StringMid() ... I just chose 30 characters as arbitrary.Typical entire string would be:$string = You attack an enemy.You attack the enemy for 223!The enemy is dead.Blah Blah Blah increased! (Now at 10%) Location: 2, 5 inArea Level Up. Health: 90% Monster Hit Points: 0/223 Gold: 690,000 Edited October 24, 2006 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 24, 2006 Share Posted October 24, 2006 (edited) Typical entire string would be:$string = You attack an enemy.You attack the enemy for 223!The enemy is dead.Blah Blah Blah increased! (Now at 10%)My routine still performs as expected. Look up in the helpfile StringInStr() and StringMid() StringInStr() tells StringMid() where to start searching the $string variable. In this case, it STARTS at the "(" in "(Now" It then extracts the next 30 characters (or to the end of the string, which ever comes first) and searches them one at a time for any numbers.Simple? Edited October 24, 2006 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 Ah, ok, I should be able to just have it finish at the second ")" then right? IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 24, 2006 Share Posted October 24, 2006 Ah, ok, I should be able to just have it finish at the second ")" then right? You could, but if the remainder of the string is shorter than 30 characters, then it's fine as is. You could tell the loop to bomb out if it finds ")" Simply add if $temp[$x] = ")" Then ExitLoop after the IsNumber() function inside the for/next Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 (edited) Ok I think I follow you now, but in: If IsNumber($temp[$x]) Then $NewString = $NewString & $temp[$x] What is the then statement doing? Is it adding the found number in the $temp array onto the $newstring? (Not working yet ) I'm not getting any numbers picked up no matter how long I extend the count in the StringMid. Edited October 24, 2006 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Blue_Drache Posted October 24, 2006 Share Posted October 24, 2006 (edited) Ok I think I follow you now, but in: If IsNumber($temp[$x]) Then $NewString = $NewString & $temp[$x] oÝ÷ ÙhZ¶+-ëaz{-jצz{]¢)à"Èi×bayú.Ùî·«{a{Múµé©jºÚÊí¢Ø^Ó~§{-®)à6p¢¹"´ò7öi趶)àj|§ºfÞ®ÊbrGºè«mz¸hÂZ'±µéݶ¢éí{ay+kxßêº^«"q©eÊ+wöËÊ)àªê-!ûaz«¶í櫬°{kzZ()àjجj{¦mêíéÚ²È Ø^½ªâi¹^Âz÷«Ûø¬jÌV¬j^اØ^ríz{l¡ûaz«¶í櫬ªºGg¯zr7öh¶Ø§¦åjy&²èÄ·ç^nè"µ8^¦ºé¢²)íâ,6éz·îËb¢r-ßÛ'¢×^µç-x)®^®®Ún¬wÁë-j»^w«-®)àêÞßÛ&È7º(u殶sf÷BgV÷C´×W7DFV6Æ&Uf'2gV÷C²Ã ¤FÒb33c·FV×Âb33c·Âb33c´æWu7G&ærÒgV÷C²gV÷C²Âb33c·7G&ærÒgV÷C´&Æ&Æ&Ææ7&V6VBb333²æ÷rBRgV÷C°¢b33c·FV×Ò7G&ætå7G"b33c·7G&ærÂgV÷C²æ÷rBgV÷C²¤×6t&÷#c#CBÂb33´FV'VrÆæRã"b33²Âb33µ6VÆV7Föã¢b33²fײÆbfײb33²b33c·FV×b33²fײÆbfײÆbfײb33µ&WGW&ã¢b33²fײÆbfײb33c·FV×fײÆbfײÆbfײb33´W'&÷#¢b33²fײÆbfײW'&÷"²222FV'VrÕ4t$õ¢b33c·FV×Ò7G&ætÖBb33c·7G&ærÂb33c·FV×Â3¤×6t&÷#c#CBÂb33´FV'VrÆæRãBb33²Âb33µ6VÆV7Föã¢b33²fײÆbfײb33²b33c·FV×b33²fײÆbfײÆbfײb33µ&WGW&ã¢b33²fײÆbfײb33c·FV×fײÆbfײÆbfײb33´W'&÷#¢b33²fײÆbfײW'&÷"²222FV'VrÕ4t$õ¢b33c·FV×Ò7G&æu7ÆBb33c·FV×ÂgV÷C²gV÷C²¤b4'&b33c·FV×FVà¢f÷"b33c·ÒFòb33c·FV׳Т6öç6öÆUw&FRb33c·FVײb33c·ÒfײÄbfײb33c´æWu7G&ærfײÄbfײgV÷C²ÒÒÒÒÒÒÒÒÒÒÒgV÷C²fײÄb¢b4çVÖ&W"b33c·FVײb33c·ÒÒFVâb33c´æWu7G&ærÒb33c´æWu7G&ærfײb33c·FVײb33c·Ð¢bb33c·FVײb33c·ÒÒgV÷C²gV÷C²FVâWDÆö÷¢æW@¤VæD`¤×6t&÷ÂgV÷C²gV÷C²Âb33c´æWu7G&ær Console: CODE >Running: (3.1.1.0):C:\AutoIt\autoit3.exe "C:\AutoIt\User Scripts\temp04.au3" ( $temp[1] $NewString ----------- N $temp[2] $NewString ----------- o $temp[3] $NewString ----------- w $temp[4] $NewString ----------- $temp[5] $NewString ----------- a $temp[6] $NewString ----------- t $temp[7] $NewString ----------- $temp[8] $NewString ----------- 1 $temp[9] $NewString ----------- 0 $temp[10] $NewString ----------- % $temp[11] $NewString ----------- ) $temp[12] $NewString ----------- >AutoIT3.exe ended. >Exit code: 0 Time: 6.566 Either way, you can see it's pulling the string out correctly, perhaps you could come up with a different method using the shortened string? Edited October 24, 2006 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 (edited) Right, I'll see what I can come up with. Thanks for the help mate. Off to lunch for now Edited October 24, 2006 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
mikehunt114 Posted October 24, 2006 Author Share Posted October 24, 2006 I worked it out from there, thanks. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 24, 2006 Moderators Share Posted October 24, 2006 prepare for the RegEx onslaught... also... a _StringBetween UDF exists... Lar.hehehe... $string = "Blah Blah Blah increased! (Now at 10%)" $Array = _SRE_BetweenEX($string, 'Now at ', '\)') MsgBox(64, '', $Array[0]) Func _SRE_BetweenEX($s_String, $s_Start, $s_End) $a_Array = StringRegExp($s_String, '(?s)(?i)' & $s_Start & '(.*?)' & $s_End, 3) If IsArray($a_Array) Then Return $a_Array Return SetError(1, 0, 0) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 24, 2006 Moderators Share Posted October 24, 2006 of course. , ok Larry, with that unknown meaning of a response, you inspired me to write this one:http://www.autoitscript.com/forum/index.ph...c=35090&hl= Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now