rasim Posted June 24, 2008 Share Posted June 24, 2008 Hi! I have a string, which mayb be like this Length: 912,260 [application/octet-stream] or this Length: 912 260 (891K) [application/octet-stream]I need to extract a 912260 substring, without whitespaces and others symbols. Link to comment Share on other sites More sharing options...
goldenix Posted June 24, 2008 Share Posted June 24, 2008 Try posting an example cuz you cant extract anything unless you know what is before or after this 912260 value.I would use Stringinstring to get the position of the substring & StringLeft(Stringinstring ) & StringLeft again to get the value, but since I dont know how big is the value & if its always constant I cant tell more. need better example My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
rasim Posted June 24, 2008 Author Share Posted June 24, 2008 goldenixThanks! Your help very useful!Need to extract a 912260 Anyone?$string = "Length: 912 260 (891K) [application/octet-stream]" MsgBox(0, "", _RegExp($string)) $string = "Length: 912,260 [application/octet-stream]" MsgBox(0, "", _RegExp($string)) Func _RegExp($sString) Local $iResult = StringRegExp($string, "Length:\s*(\d.*) \(" , 1) If @error Then Return False Return $iResult[0] EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 24, 2008 Moderators Share Posted June 24, 2008 $string = "Length: 912 260 (891K) [application/octet-stream]" $nNum = StringRegExpReplace($string, "(?s)(?i)(length:\s)(\d+)(\s)(\d+)([\D\d]+)", "\2\4") ConsoleWrite($nNum & @CRLF) 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...
rasim Posted June 24, 2008 Author Share Posted June 24, 2008 (edited) SmOke_NThank you! But string can be looks like "Length: 912,260 265 768 (891K) [application/octet-stream]" or Length: 912,260,278,536[application/octet-stream]I don`t now how many "red" numeral exists. I need to extract all "red" numeral. Edited June 24, 2008 by rasim Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 24, 2008 Moderators Share Posted June 24, 2008 (edited) SmOke_N Thank you! But string can be looks like "Length: 912,260 265 768 (891K) [application/octet-stream]" or Length: 912,260,278,536[application/octet-stream] I don`t now how many "red" numeral exists. I need to extract all "red" numeral. Too tired to figure out another way:$string = "Length: 912 260 (891K) [application/octet-stream]" $sNum = StringRegExpReplace(StringRegExpReplace($string, "(?s)(?i)Length:\s*(.+?)\s*[\(\[][\D\d]+", "\1"), "\D+", "") ConsoleWrite($sNum & @CRLF) Edited June 24, 2008 by SmOke_N 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...
xshark Posted June 24, 2008 Share Posted June 24, 2008 (edited) Took your original example and believe this will work. . . as long as the format stays fairly similar. Sometimes you need to approach the problem from the other side $string = "Length: 912 260 (891K) [application/octet-stream]" MsgBox(0, "", _RegExp($string)) $string = "Length: 912,260 [application/octet-stream]" MsgBox(0, "", _RegExp($string)) Func _RegExp($sString) $sString = StringRegExpReplace($sString, "\(\d*K\)",""); Remove all patters similar to "(###K)" or "(K)" or "(#####K)" $iResult = StringRegExpReplace($sString,"[^\d]",""); Remove all patters that are not digits. If StringIsInt($iResult) = 0 Then Return False Return $iResult EndFunc Edited June 24, 2008 by xshark Link to comment Share on other sites More sharing options...
rasim Posted June 24, 2008 Author Share Posted June 24, 2008 SmOke_NOk! Thank you! Link to comment Share on other sites More sharing options...
goldenix Posted June 24, 2008 Share Posted June 24, 2008 if this nr will always stay 15 chars long then how about this? $string = 'aba Length: 912,260 265 768 (891K) [application/octet-stream] or Length: 912,260,278,536[application/octet-stream] Length: 912,260 265 768 (891K) [ap Length: 912,260 265 768 (891K) [ap' For $e = 1 to 999999999999999 $loc = StringInStr($string, "Length: ", 2, $e) If $loc = 0 then ExitLoop $ar = StringMid ($string, $loc+8 , 15 ) ConsoleWrite($ar & @CRLF) Next My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] 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