Bot 1 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. Share this post Link to post Share on other sites
SmOke_N 211 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. Share this post Link to post Share on other sites
BrettF 28 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! Share this post Link to post Share on other sites
SmOke_N 211 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. Share this post Link to post Share on other sites
BrettF 28 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! Share this post Link to post Share on other sites
Bot 1 Posted September 27, 2007 Thank you very much for your help . I'm really suck a newbie with AutoIT Share this post Link to post Share on other sites