StringInStr returns wrong position

6 posts in this topic

Hi all,

I´m new to AutoIT so you can imagine, that I know very little about how the functions work in detail. 

I have the problem that the StringInStr function when searching for a string in the sourcecode of different webpages returns the wrong position of the searched string. I know, that the sourcecode is tens of thousands characters long and the searched string is about in the middle, but the function returns only 28.

Also StringLen for example returns about 33000, but i know the sourcecode is much longer.

Please note, that the pages have a similar structure only with different titles etc. and for the most pages my script works exactly as intended.

Is there some kind of length limitation of the source for these functions to show the right numbers (because the count maybe begins from the start at a certain point)? 

Thank you in advance for your help.

Share this post

Link to post
Share on other sites

You can specify where the search starts or how many characters need to be searched by using the fifth and sixth parameters. See the helpfile for StringInStr for more information. If you do not use those, you shouldn't run into limits any time soon.

Without more information it's impossible to give more support. Please show what you have coded so people here can offer suggestions. The best thing would be an actual example of a string search that goes wrong including the string in which you are searching.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post

Link to post
Share on other sites

I've never had any problems with StringInStr() not returning the expected result. What is the string you are searching for and what is the string you are searching? Without this information no one is going to be able to offer you any help/ 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post

Link to post
Share on other sites

No issue with latest version of AutoIt.

#include <MsgBoxConstants.au3>

MsgBox($MB_SYSTEMMODAL, '', StringInStr('Testing if StringInStr() is broken', 'if')) ; Should be 9.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post

Link to post
Share on other sites

Here is the reading part of my script so far: 

#include <INet.au3>
#include <Misc.au3>
#include <Excel.au3>
Opt ("WinTitleMatchMode", 2)
While 1
Until _IsPressed("12") and _IsPressed("44") ;12 for Alt, 44 for D --> marks the link in the current tab
Send( "^c") 
If WinExists ( "Mods.xls", "") = 1 Then
WinActivate ( "Mods.xls", "")
WinWaitActive( "Mods.xls", "") 
Local $oExcel = _Excel_Open() 
Local $sWorkbook = @DesktopDir & "\Mods.xlsx" 
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, Default, Default, True) 
WinActivate ( "Mods.xls", "")
WinWaitActive( "Mods.xls", "") 

Local $sURL = ClipGet() 
Local $sSource = _INetGetSource ( $sURL,True ) 

Local $iLength = StringLen ( $sSource)
MsgBox ( 0, "Length, String($iLength))
Local $sSearch1 = '<span class="header-name">'
Local $iPos1 = StringInStr ( $sSource, $sSearch1, 0, 1) + StringLen ( $sSearch1 )
MsgBox ( 0, "Position 1", String($iPos1))

Local $sSearch2 = "</span>"
Local $iPos2 = StringInStr ( $sSource, $sSearch2, 0, 1, $iPos1)
MsgBox ( 0, "Position 2", String($iPos2))

Local $sModName = StringMid ( $sSource, $iPos1, $iPos2 - $iPos1 )
MsgBox ( 0, "Modname alt", $sModName)


The final aim is to write different infos regarding skyrim modifications from example the mod name in this case) into an excel document.

Here two example links to the source codes of two modpages:


for this site, the function works


for this site, it doesn´t work

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forum. :)

Unfortunately you appear to have missed the >Forum rules on your way in. Please read them now (there is also a link at bottom right of each page) - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. :naughty:

See you soon with a legitimate question I hope. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites
This topic is now closed to further replies.