Bot Posted September 27, 2007 Posted September 27, 2007 $text = "AutoIt has a StringInStr function. And StringInStr is to check if a string contains a given substring." There are 2 occurrences of the text "StringInStr" in the $text but how can I return the positions of them in this ? Thanks.
Moderators SmOke_N Posted September 27, 2007 Moderators Posted September 27, 2007 (edited) #include <array.au3> $text = "AutoIt has a StringInStr function. And StringInStr is to check if a string contains a given substring." $aPos = _StringGetPos($text, "StringInStr", 1, 1) _ArrayDisplay($aPos, "StringInStr Pos") Func _StringGetPos($sText, $sFind, $nAll = 0, $nCase = 0) If $nAll Then Local $aSplit = StringSplit($sText, $sFind, 1) Local $avArray[$aSplit[0]] $avArray[0] = $aSplit[0] If $aSplit[0] > 0 Then For $iCC = 1 To $aSplit[0] - 1 $avArray[$iCC] = StringInStr($sText, $sFind, $nCase, $iCC) Next Return $avArray EndIf Return SetError(1, 0, 0) EndIf Local $avArray[2] = [1, StringInStr($sText, $sFind, $nCase)] If $avArray[1] <> 0 Then Return $avArray Return SetError(2, 0, 0) EndFuncoÝ÷ ØGb´bëaÊ'y·µêÚºÚ"µÍÚ[ÛYH Ø^K]LÉÝÂÌÍÝ^H ][ÝÐ]]Ò]ÈHÝ[Ò[Ý[Ý[Û[Ý[Ò[ÝÈÈÚXÚÈYHÝ[ÈÛÛZ[ÈHÚ][ÝXÝ[Ë][ÝÂÌÍØTÜÈHÔÝ[ÑÙ]ÜÊ ÌÍÝ^ ][ÝÔÝ[Ò[Ý][ÝËKJBÐ^QÜ^J ÌÍØTÜË ][ÝÔÝ[Ò[ÝÜÉ][ÝÊB[ÈÔÝ[ÑÙ]ÜÊ ÌÍÜÕ^ ÌÍÜÑ[ ÌÍÛ[H ÌÍÛØÙHH BRY ÌÍÛ[[BTÝ[ÔXÙJ ÌÍÜÕ^ ÌÍÜÑ[ ][ÝÉ][ÝÊBBSØØ[ ÌÍÛ^[YH^[YBSØØ[ ÌÍØ]^VÉÌÍÛ^[Y ÌWBBIÌÍØ]^VÌHH ÌÍÛ^[YBRY ÌÍÛ^[Y ÝÈ[BBQÜ ÌÍÚPÐÈHHÈ ÌÍÛ^[YBBBIÌÍØ]^VÉÌÍÚPÐ×HHÝ[Ò[Ý ÌÍÜÕ^ ÌÍÜÑ[ ÌÍÛØÙK ÌÍÚPÐÊBBBS^BBT] ÌÍØ]^BBQ[YBT]Ù]ÜK BQ[YSØØ[ ÌÍØ]^VÌHHÌKÝ[Ò[Ý ÌÍÜÕ^ ÌÍÜÑ[ ÌÍÛØÙJWBRY ÌÍØ]^VÌWH ÉÝÈ[] ÌÍØ]^BT]Ù]Ü B[[ Edited September 27, 2007 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.
BrettF Posted September 27, 2007 Posted September 27, 2007 This is how I did it... Pretty much like Smokes second one... But his is better Func _StringInStr ($sString, $sSubstring, $iCasesense = 0) $strings = StringReplace ($sString, $sSubstring, $sSubstring, 0, $iCasesense) $number = @extended Local $aArray[$number + 1] $aArray[0] = $number For $i = 1 to $number $aArray[$i] = StringInStr ($sString, $sSubstring, $iCasesense, $i) Next Return $aArray EndFunc Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Moderators SmOke_N Posted September 27, 2007 Moderators Posted September 27, 2007 (edited) This is how I did it... Pretty much like Smokes second one... But his is better Func _StringInStr ($sString, $sSubstring, $iCasesense = 0) $strings = StringReplace ($sString, $sSubstring, $sSubstring, 0, $iCasesense) $number = @extended Local $aArray[$number + 1] $aArray[0] = $number For $i = 1 to $number $aArray[$i] = StringInStr ($sString, $sSubstring, $iCasesense, $i) Next Return $aArray EndFuncThat will return an array regardless of whether the string to search even contains the pattern to find. Edit: Typo Edited September 27, 2007 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.
BrettF Posted September 27, 2007 Posted September 27, 2007 That will return an array regardless of whether the string to search even contains the pattern to find.Edit:TypoWoops... My Bad Hence why your's is better... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Bot Posted September 27, 2007 Author Posted September 27, 2007 Thank you very much for your help . I'm really suck a newbie with AutoIT
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