pingpong24 Posted January 1, 2006 Share Posted January 1, 2006 hi, i need extract certin data of a string i.e. $String = "http://www.autoitscript.com/forum/index.php?act=post&do=new_post&f=2" i want to extract: A: "/forum/inde.php?" B: "act= verable" just the verable then replace the verable, so i want basically change act="POST" to act=$verable I tried using StringReplace and but didnt work. in otherwords how do i search for certin phase in a string and say: $string = "123abcdefghijklk456789" find inside $string, then from "3" to "4" store as $X and i want to do this also $string = "123abcdefgh4567" replace what is between "3" and "4" with $x thank you sorry i couldnt make it any clear NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
Rick Posted January 1, 2006 Share Posted January 1, 2006 (edited) you almost have it; $First=find 1st string in variable to get position $second=then find second $count=$second-$first-1 then $middle=stringmid $var,$first, $count $firstbit=stringmid $var,1, $first-1 $lastbit=stringmid $var,$second+1 $string= $firstbit & $middle & $lastbit does that help?? Edited January 1, 2006 by Rick Who needs puzzles when we have AutoIt!! Link to comment Share on other sites More sharing options...
jonk Posted January 1, 2006 Share Posted January 1, 2006 (edited) in otherwords how do i search for certin phase in a string and say: $string = "123abcdefghijklk456789" find inside $string, then from "3" to "4" store as $X and i want to do this also $string = "123abcdefgh4567" replace what is between "3" and "4" with $x thank you sorry i couldnt make it any clear to find or replace a string in a string wich must match a special Pattern try StringRegExpReplace $string = "123abcdefghijklk456789" $newString = StringRegExpReplace($string,"[a-zA-Z]+","yourString") If @error = 0 Then msgbox(64,"Result",$newString) ElseIf @error = 1 Then msgBox(64,"Error","Count invalid") ElseIF @error = 2 Then msgBox(64,"Error","Pattern invalid") EndIf ... you need a betaversion for this example .... Edited January 1, 2006 by jonk Link to comment Share on other sites More sharing options...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 sorry, no of this helped. sorry i think i didnt make clear: $string = "gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283" from that string say i wanted to extract some data $name = somefunction($string, jka -to- 62) this imaginry funcation would extract from the string "jka" 'jkgjalsgjls' "62" jka = starting point 62 = end thats all i want to do, not extract jka, or 62 but use that as a starting point and end. i can do it in php very easily. how can i do it in AUTOIT NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
jonk Posted January 1, 2006 Share Posted January 1, 2006 $string = "gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283" ;~ "jka" 'jkgjalsgjls' "62" $a_Result = StringRegExp($string,"(jka)([^62]*)",1) If @error = 0 Then msgbox(64,"Result",$a_Result[1]) ElseIf @error = 1 Then msgBox(64,"Error","Count invalid") ElseIF @error = 2 Then msgBox(64,"Error","Pattern invalid") EndIf well, some slight changes...and tadaaa? Link to comment Share on other sites More sharing options...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 arrrrrgh i am trying it to implement it on my script i cant figure out how to use it, this funcation is so retarded and documentation sucks who ever wrote it should be shoot. arrrgh 2 hours spent and cant get it to work. why not just make it simple like this : StringRegExp($string, (begaing)(end)) had to be extra and add other stuff. oh well ill just pm the string to jonk and get him to do the pattern. NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
jonk Posted January 1, 2006 Share Posted January 1, 2006 arrrrrgh i am trying it to implement it on my script i cant figure out how to use it, this funcation is so retarded and documentation sucks who ever wrote it should be shoot.arrrgh 2 hours spent and cant get it to work.why not just make it simple like this : StringRegExp($string, (begaing)(end))had to be extra and add other stuff.oh well ill just pm the string to jonk and get him to do the pattern.jep, regular expressions sometimes make me mad too . I am using a nicetool to test my patterns:RegExp-Coach Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 1, 2006 Moderators Share Posted January 1, 2006 arrrrrgh i am trying it to implement it on my script i cant figure out how to use it, this funcation is so retarded and documentation sucks who ever wrote it should be shoot. arrrgh 2 hours spent and cant get it to work. why not just make it simple like this : StringRegExp($string, (begaing)(end)) had to be extra and add other stuff. oh well ill just pm the string to jonk and get him to do the pattern. Well, I find the documentation really good personally, I think if I'm ever unclear about something, it's not a poor documentation example, it's poor misinterpretation on my behalf. Dim $String = 'gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283' Dim $Starting = 'jka' Dim $Ending = '62' MsgBox(0, "Test", _GetString($String, $Starting, $Ending)) Func _GetString($String, $Starting, $Ending) Local $OutPut = '' $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) Return $SeL 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 January 1, 2006 Moderators Share Posted January 1, 2006 Here's the first Method I did, and the second one is using jonk's idea using StringRegExpReplace()... This should get you going at least, making them into little UDF's. Dim $String = 'gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283' Dim $Starting = 'jka' Dim $Ending = '62' MsgBox(0, "Test", _GetStringMethod1($String, $Starting, $Ending)) Func _GetStringMethod1($String, $Starting, $Ending) $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) Return $SeL EndFunc MsgBox(0, "Test2", _GetStringMethod2($String, $Starting, $Ending)) Func _GetStringMethod2($String, $Starting, $Ending) $a_Result = StringRegExp($String,'('&$Starting&')([^'&$Ending&']*)',1) If @error = 0 And @extended Then Return $Starting & $a_Result[1] & $Ending 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...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 thank you guys fro trying to help though non of your script helped me at all. smokn you came close but your script returns the ending.. so that wasnt any help and it was hard to understand your script Func _RequestString($String, $Starting, $Ending) $startingsize = StringLen($Starting) $endsize = StringLen($Ending) + $startingsize + 3 $location1 = StringInStr($String, $Starting, 1) + $startingsize MsgBox(0,"",$location1) $location2 = StringInStr($String, $Ending, 1) - $endsize MsgBox(0,"",$endsize) $result = StringMid($String, $location1, $location2) Return $result EndFunc there you i hope they add this to the autoitUDF NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
jonk Posted January 1, 2006 Share Posted January 1, 2006 thank you guys fro trying to help though non of your script helped me at all. so that wasnt any helpwhat about the script I pm you? $string = "http://url/announce.php?passkey=ba5e00c1a3272c7cf970f40acdffac4c?info_hash=%7DM%D0%98%0Ef%0B%E2%A2%16I%00%C5%05%8B%F4%BF%E9J%3F&peer_id=%2DBC0060%2D2%2D0%87z%1D%BF%88p2%8F%1E&port=6999&natmapped=1&localip=127.0.0.1&uploaded=0&downloaded=0&left=0&numwant=200&compact=1&no_peer_id=1&key=18478&event=started%22%22" ;~ "jka" 'jkgjalsgjls' "62" $a_Result = StringRegExp($string,"=([^&]*)",3) If @error = 0 Then if isArray($a_Result) then for $i=0 to ubound($a_Result)-1 Step 1 msgbox(64,"Result",$a_Result[$i]) next EndIf ElseIf @error = 1 Then msgBox(64,"Error","Count invalid") ElseIF @error = 2 Then msgBox(64,"Error","Pattern invalid") EndIf it worked for me. Link to comment Share on other sites More sharing options...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 yeah yours works.. but too messy and i need to replicate it for alot of other strings. anyways thank you and smOke for trying to help. NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 1, 2006 Moderators Share Posted January 1, 2006 thank you guys fro trying to help though non of your script helped me at all. smokn you came close but your script returns the ending.. so that wasnt any help and it was hard to understand your script Func _RequestString($String, $Starting, $Ending) $startingsize = StringLen($Starting) $endsize = StringLen($Ending) + $startingsize + 3 $location1 = StringInStr($String, $Starting, 1) + $startingsize MsgBox(0,"",$location1) $location2 = StringInStr($String, $Ending, 1) - $endsize MsgBox(0,"",$endsize) $result = StringMid($String, $location1, $location2) Return $result EndFunc there you i hope they add this to the autoitUDF If my script was "hard" to understand, then I can see why your having trouble with the help file. Maybe you should explain in more detail next time exactly what you want to do. If you didn't want the 'Starting' or 'Ending' strings to be in the string pulled, then you should have stated that, btw... your's still leaves the first delimeter '6' or the '62' in the string, was that a desired affect, because I didn't see that either. Dim $String = 'gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283' Dim $Starting = 'jka' Dim $Ending = '62' ; just the string between the $Starting and $Ending MsgBox(0, "Test1", _GetStringMethod($String, $Starting, $Ending)) Func _GetStringMethod($String, $Starting, $Ending) $a_Result = StringRegExp($String,'('&$Starting&')([^'&$Ending&']*)',1) If @error = 0 And @extended Then Return $a_Result[1] EndFunc ; with your 1st delimeter 'Ending' string still there MsgBox(0, "Test1", _GetStringMethod2($String, $Starting, $Ending)) Func _GetStringMethod2($String, $Starting, $Ending) $a_Result = StringRegExp($String,'('&$Starting&')([^'&$Ending&']*)',1) If @error = 0 And @extended Then Return $a_Result[1] & StringLeft($Ending, 1) EndFunc Next time giving an example (which one of your post explained a 'bit') give the 'Exact Desired' output you want to receive: this imaginry funcation would extract from the string "jka" 'jkgjalsgjls' "62" your example here, I interpreted to mean that you wanted all 3 of those strings in one. 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...
pingpong24 Posted January 1, 2006 Author Share Posted January 1, 2006 Ah thanks very much SmOke_N, my script had a problem when you change the size of begaing and end.. it doesnt work. thank you very much!! keep up the good work NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum 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