EndFunc Posted May 27, 2010 Share Posted May 27, 2010 (edited) I have a line of text and when I try to trim the right it gives weird results. Example $sPath = "C:\scripts\autoit\mypath\morescripts\file.exe" When I do this $nPath = StringTrimRight($sPath,StringInStr($sPath,"\",0, -1)) It returns something weird like C:\scripts\autoit\mypath\mores Instead of C:\scripts\autoit\mypath\morescripts\ What am I doing wrong cause my brain must be fried right now. Edited May 27, 2010 by EndFunc EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
MrMitchell Posted May 27, 2010 Share Posted May 27, 2010 (edited) Your StringInStr is returning position of the rightmost "\" starting from the left side which is like the 37th character. So 37 characters are being trimmed from the right side of the string. Add: Something like this could work... ; ; $nPath = StringTrimRight($sPath,StringLen($sPath) - StringInStr($sPath,"\",0, -1)) ; ; Edited May 27, 2010 by MrMitchell Link to comment Share on other sites More sharing options...
jchd Posted May 27, 2010 Share Posted May 27, 2010 (edited) Reread the definition of StringInStr output, then the definition of StringTrimRight second parameter. Then realize that the result of the former can't be (in your case) used directly by the latter! Edit: I was diverted and overtaken! Simpler: $nPath = StringLeft($sPath, StringInStr($sPath,"\",0, -1)) Edited May 27, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Bowmore Posted May 27, 2010 Share Posted May 27, 2010 (edited) StringLeft will give the answer you are looking for. $sPath = "C:\scripts\autoit\mypath\morescripts\file.exe" $nPath = StringLeft($sPath,StringInStr($sPath,"\",0, -1)) Edited May 27, 2010 by Bowmore "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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 27, 2010 Moderators Share Posted May 27, 2010 (edited) MrMitchell pointed out what you needed with StringTrimRight ... You could have used StringLeft to achieve the same results the way you originally had it though:$nPath = StringLeft($sPath, StringInStr($sPath,"\",0, -1))Edit:As Bowmore showed Edit2:And as jchd presented in his edit Edited May 27, 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...
EndFunc Posted May 27, 2010 Author Share Posted May 27, 2010 Your StringInStr is returning position of the rightmost "\" starting from the left side which is like the 37th character. So 37 characters are being trimmed from the right side of the string. Add: Something like this could work... ; ; $nPath = StringTrimRight($sPath,StringLen($sPath) - StringInStr($sPath,"\",0, -1)) ; ; Ahh,doh.. That makes sense. I guess I was confusing myself. Thanks for the help and setting me straight. EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
EndFunc Posted May 27, 2010 Author Share Posted May 27, 2010 MrMitchell pointed out what you needed with StringTrimRight ... You could have used StringLeft to achieve the same results the way you originally had it though:$nPath = StringLeft($sPath, StringInStr($sPath,"\",0, -1)) Edit: As Bowmore showed Thanks SmOke_N, that is actually what I was trying to do because I had done it before but couldn't understand why it wasn't working. Wrong function. lol I should try and find my old scripts as reference. 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