Dracil Posted May 20, 2010 Share Posted May 20, 2010 Hello i need a little help. Lets say i have a string with "Army Troops : 1000 x" The number 1000 changes all the time, so how do i grab something by between the ":" and then "x" ? Thanks in advance bikerbrooks 1 Link to comment Share on other sites More sharing options...
enaiman Posted May 20, 2010 Share Posted May 20, 2010 StringSplit for ":" then get rid of anything but the number from the 2nd element. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 20, 2010 Moderators Share Posted May 20, 2010 (edited) The search feature ( though not as good as it once was ) still works for simple things:http://www.autoitscript.com/forum/index.php?app=core&module=search§ion=search&do=quick_search&search_app=core&fromsearch=1Well that link is useless. Doesn't show the query or provide the link to the searched term.Anyway, if you looked at the "search" feature, typed in "text"+"between" and titles only, this would have been your first popup:http://www.autoitscript.com/forum/index.php?showtopic=103623&view=findpost&p=733863&hl=%22text%22+%22between%22&fromsearch=1That one does show the query, but it also has your answer. Edited May 20, 2010 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...
Lee Bussy Posted May 20, 2010 Share Posted May 20, 2010 (edited) Something along these lines would get you close: ; Split string at the ":", return array $fields = StringSplit ( "Army Troops : 1000 x", ":") ; Remove the right most character (StringTrimRoght) and ; strip white space from the second element in the split ; array (StringStripWS) $yournumber = StringStripWS(StringTrimRight( $fields[2], 1 )) ... untested but it should be real close. EDIT: Doh, people answered as I was typing. Edited May 20, 2010 by Lee Bussy Link to comment Share on other sites More sharing options...
Malkey Posted May 20, 2010 Share Posted May 20, 2010 Here is another four (4) methods for getting the text between two (2) search letters in a string. #include <String.au3> Local $sStr = "Army Troops : 1000 x" Local $iStart = StringInStr($sStr, ":") + 1 ConsoleWrite("StringMid = " & StringMid($sStr, $iStart, StringInStr($sStr, "x") - $iStart) & @CRLF) Local $aArray = _StringBetween($sStr, ":", "x") ConsoleWrite("_StringBetween = " & $aArray[0] & @CRLF) Local $aArrayRE = StringRegExp($sStr, ":(.*)x", 1) ConsoleWrite("StringRegExp = " & $aArrayRE[0] & @CRLF) ConsoleWrite("StringRegExpReplace = " & StringRegExpReplace($sStr, ".*:(.*)x.*", "\1") & @CRLF) Link to comment Share on other sites More sharing options...
sahsanu Posted May 21, 2010 Share Posted May 21, 2010 (edited) Lets say i have a string with "Army Troops : 1000 x" The number 1000 changes all the time, so how do i grab something by between the ":" and then "x" ? Here we go with another possible solution ;-) Local $sStr = "Army Troops : 1000 x" Local $sResult=StringRegExpReplace($sStr,"(.*?)([0-9]{1,})(.*)","$2") ConsoleWrite('$sResult = ' & $sResult & @CRLF) I hope this helps. Have a nice day. sahsanu Edited May 21, 2010 by sahsanu 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