sroprogger Posted February 6, 2009 Share Posted February 6, 2009 Okay here's my idea I want to read a specific line of a text document, search it for a specific word and display that word as a label in my GUI Now my problem is The word can differ, it can be 6 different words like: hello,no,yes,maybe,sir,yellow i did some research and found this StringRegExp and StringInStr - but they just give me numbers and i dont really know how to use them The help file doesnt help me at all because i dont understand it well thx for your answers Link to comment Share on other sites More sharing options...
TerarinK Posted February 6, 2009 Share Posted February 6, 2009 $sValue = "Hello, this is a test." If StringRegExp($sValue, "(?i:hello|no|yes|maybe|sir|yellow)", 0) Then DoWhateverYouWant() 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E Link to comment Share on other sites More sharing options...
sroprogger Posted February 6, 2009 Author Share Posted February 6, 2009 $sValue = "Hello, this is a test." If StringRegExp($sValue, "(?i:hello|no|yes|maybe|sir|yellow)", 0) Then DoWhateverYouWant() well - when i did this i got 1 on success - 0 on failure Now that CAN help me - but im looking for an easier way since i would have to write 200 lines of code just for one thing using StringRegExp -because there is actually 200 posibilities - now is there a way to search a string - lets say 'hello<"name = 77618">' - for the value after 'hello<"name = ... and then save it to another string ? if so could you please tell me thx for your answers Link to comment Share on other sites More sharing options...
CodyBarrett Posted February 6, 2009 Share Posted February 6, 2009 Strininstr() OR stringtrimleft() Stringtrimright() OR stringreplace() whatever you need please CHECK THE HELP FILE its your best friend in autoit [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
sroprogger Posted February 6, 2009 Author Share Posted February 6, 2009 Strininstr() OR stringtrimleft() Stringtrimright() OR stringreplace() whatever you need please CHECK THE HELP FILE its your best friend in autoit but all those expressions do is check if that word is in there - is there an expression that can read a specific word at a specific place and then diplay it onto the gui ? if not ill have to go with the other expressions - but 200 lines of code x.x well thx for your answers Link to comment Share on other sites More sharing options...
Inverted Posted February 6, 2009 Share Posted February 6, 2009 (edited) If you know what's before and after the string, then you can use StringBetween. You need to know something about the location of the string, it can't be found magically ! Edited February 6, 2009 by Inverted Link to comment Share on other sites More sharing options...
Malkey Posted February 6, 2009 Share Posted February 6, 2009 well - when i did this i got 1 on success - 0 on failure Now that CAN help me - but im looking for an easier way since i would have to write 200 lines of code just for one thing using StringRegExp -because there is actually 200 posibilities - now is there a way to search a string - lets say 'hello<"name = 77618">' - for the value after 'hello<"name = ... and then save it to another string ? if so could you please tell me thx for your answersThis may give you some ideas. #include <Array.au3> ; From post ; http://www.autoitscript.com/forum/index.php?s=&showtopic=89105&view=findpost&p=640323 ; - lets say 'hello<"name = 77618' - for the value after 'hello<"name = ... and ; then save it to another string ? $sString = 'Extra text here hello<' & '"' & 'name = 77618' & '"' & '> and here' ; That which is found between the brackets, (), is returned to the array. ; This case: \d is any digit. * means repeat the previous character 0 or more times. ; So this will search the $sString for the text in the regular expression, and will ; return all occurances of the digits, if any, that appear after [hello<"name = ] and ; before [">] $array = StringRegExp($sString, 'hello<' & '"' & 'name = (\d*)' & '"' & '>' , 3) _ArrayDisplay($array) $sAnotherString = _ArrayToString($array) MsgBox(0,"A String",$sAnotherString) #cs ; Easier to search whole of file instead of one line at a time.Will return an array ; of all matches. $sFile = "FullPath\and\FileName.txt" ; Full path if not in same script directory. $sRegExp = 'hello<' & '"' & 'name = (\d*)' & '"' & '>' StringRegExp(FileRead($sFile), $sRegExp , 3) #ce Link to comment Share on other sites More sharing options...
sroprogger Posted February 7, 2009 Author Share Posted February 7, 2009 (edited) This may give you some ideas. #include <Array.au3> ; From post ; http://www.autoitscript.com/forum/index.php?s=&showtopic=89105&view=findpost&p=640323 ; - lets say 'hello<"name = 77618' - for the value after 'hello<"name = ... and ; then save it to another string ? $sString = 'Extra text here hello<' & '"' & 'name = 77618' & '"' & '> and here' ; That which is found between the brackets, (), is returned to the array. ; This case: \d is any digit. * means repeat the previous character 0 or more times. ; So this will search the $sString for the text in the regular expression, and will ; return all occurances of the digits, if any, that appear after [hello<"name = ] and ; before [">] $array = StringRegExp($sString, 'hello<' & '"' & 'name = (\d*)' & '"' & '>' , 3) _ArrayDisplay($array) $sAnotherString = _ArrayToString($array) MsgBox(0,"A String",$sAnotherString) #cs ; Easier to search whole of file instead of one line at a time.Will return an array ; of all matches. $sFile = "FullPath\and\FileName.txt" ; Full path if not in same script directory. $sRegExp = 'hello<' & '"' & 'name = (\d*)' & '"' & '>' StringRegExp(FileRead($sFile), $sRegExp , 3) #ce i still dont get it .... ive been trying to understand it for 2 hours , reading the helfile, searching the forum, i just dont get it ! could you maybe do another example using the code i'll be using so $a = <option name="HP_LOW" value="85" /> [ find the value after 'value="... ] Thx for your answers EDIT:: with the _StringBetween heres the code im trying to use $a = '<option name="HP_LOW" value="85" />' $string_between = _StringBetween($a,'value="','" />') MsgBox(0,"",$string_between) but it doesn't work - what am i doing wrong ? Edited February 7, 2009 by sroprogger Link to comment Share on other sites More sharing options...
Inverted Posted February 7, 2009 Share Posted February 7, 2009 #Include <string.au3> $a = '<option name="HP_LOW" value="85" />' $string_between = _StringBetween($a,'value="','" />') MsgBox(0,"",$string_between[0]) Helpfile says : "Return Value Success: A 0 based $array[0] contains the first found string. " Link to comment Share on other sites More sharing options...
Authenticity Posted February 7, 2009 Share Posted February 7, 2009 #include <String.au3> $a = '<option name="HP_LOW" value="85" />' $string_between = _StringBetween($a,'value="','" />') MsgBox(0,"",$string_between[0]) Read carefully the remarks as well as the parameters and return value. Link to comment Share on other sites More sharing options...
sroprogger Posted February 7, 2009 Author Share Posted February 7, 2009 thx to you all !!!!!! thank you so much *happy* i figured it out and its working perfetly now !! its so cool i love you haha ^^ well thank you for helping me ! Link to comment Share on other sites More sharing options...
TerarinK Posted February 7, 2009 Share Posted February 7, 2009 You could also do this: $sValue = '<option name="HP_LOW" value="85" />' StringRegExp($sValue, "(?i)="(\w*)"", 3) This will give you both HP_LOW and 85 in a array 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E 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