EndFunc Posted February 25, 2009 Share Posted February 25, 2009 Every time I try StringinStr, it returns a number. EVen the example helpfile returns 10 instead of the the word that it shows. I have 3.3.0.0 Anybody else have this problem? EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
jvanegmond Posted February 25, 2009 Share Posted February 25, 2009 xD StringInStr is SUPPOSED to return a number. It returns the index of the string that is found. github.com/jvanegmond Link to comment Share on other sites More sharing options...
EndFunc Posted February 25, 2009 Author Share Posted February 25, 2009 xD StringInStr is SUPPOSED to return a number. It returns the index of the string that is found. Hmm, am I using it wrong because I don't remember it doing that. What is it supposed do here? $result = StringInStr("I am a String", "RING") MsgBox(0, "Search result:", $result) $location = StringInStr("How much wood could a woodchuck chuck is a woodchuck could chuck wood?", "wood", 0, 3) ; Find the 3rd occurance of "wood" The number 10 would make no sense. EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25, 2009 Moderators Share Posted February 25, 2009 It starts at the 10th character of the string, it makes perfect sense. 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...
EndFunc Posted February 25, 2009 Author Share Posted February 25, 2009 It starts at the 10th character of the string, it makes perfect sense.I see, yeah I understand. Maybe I'm think of StringSplit.Ok say Im trying to get the folder name in a path and wanting to get the name after the last "\" in the string. That is what I was attempting to do. It was giving me a number but I believe I got them confused. Any suggestion on how to do this the most efficient way. I was also using a -1 to make it start on the right side which further confused me. lol EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
Authenticity Posted February 25, 2009 Share Posted February 25, 2009 (edited) Dim $aPath_FileName = StringRegExp($sPath, (.+\\)(.+), 3) This will return the path plus the '\' in the first element of the array and the 'filename.ext' in the second element, or, fail in case of strings like 'Notepad.exe', 'C:\Games\' etc.. Edited February 25, 2009 by Authenticity Link to comment Share on other sites More sharing options...
EndFunc Posted February 26, 2009 Author Share Posted February 26, 2009 Dim $aPath_FileName = StringRegExp($sPath, (.+\\)(.+), 3)This will return the path plus the '\' in the first element of the array and the 'filename.ext' in the second element, or, fail in case of strings like 'Notepad.exe', 'C:\Games\' etc..Ok I will check it out. I wanted to retrieve the very last folder in the path and single that out and you wont know how long the directory is. EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 26, 2009 Moderators Share Posted February 26, 2009 Dim $aPath_FileName = StringRegExp($sPath, (.+\\)(.+), 3) This will return the path plus the '\' in the first element of the array and the 'filename.ext' in the second element, or, fail in case of strings like 'Notepad.exe', 'C:\Games\' etc..StringRegExpReplace($sPath, "(.+?[\\/]+)+(.+?\z)", "\2") 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...
Authenticity Posted February 26, 2009 Share Posted February 26, 2009 So StringSplit it and the filename will be $aSplit[$aSpilt[0]] and the last folder in $aSplit[$aSplit[0]-1]. Link to comment Share on other sites More sharing options...
herewasplato Posted February 26, 2009 Share Posted February 26, 2009 ... I was also using a -1 to make it start on the right side which further confused me.$sPath = "c:\1st\2nd\3rd\4th\5th\file.txt" $last = StringInStr($sPath, "\", 0, -1) $next2last = StringInStr($sPath, "\", 0, -1, ($last - 1)) $lastFolder = StringMid($sPath, ($next2last + 1), ($last - 1) - $next2last) MsgBox(0, "StringMid", $lastFolder) ;or per Authenticity $PathArray = StringSplit($sPath, "\") MsgBox(0, "StringSplit", $PathArray[$PathArray[0] - 1]) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 26, 2009 Share Posted February 26, 2009 Since you want two pieces, you can use _PathSplit, or alternatively here's a quick path-split call: $aSplitPath=StringRegExp($sPath,'([^\\\:]+)',3) Given C:a folder\a file, it will return an array like this: [0] = C [1] = a folder [2] = a file Given C:\a\complete\path\filename.ext, it will return [0] = C [1] = a [2] = complete [3] = path [4] = filename.ext Ascen4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
WolfWorld Posted February 26, 2009 Share Posted February 26, 2009 Is this like the PathSplit or SplitPath (Cant remember) UDF? If so use that. Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
EndFunc Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks all for the suggestions. I actually don't care about the file. There is no file I'm looking for. Just the very last folder/directory. C:\1\2\3\4\5\6\7. So in that, it would be 7, some cases I won't know what the last folder will be. I will play around with these and see what I come up with. EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
EndFunc Posted February 26, 2009 Author Share Posted February 26, 2009 So StringSplit it and the filename will be $aSplit[$aSpilt[0]] and the last folder in $aSplit[$aSplit[0]-1]. works great. Thank you for this. EndFuncAutoIt is the shiznit. I love it. 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