StuckUser Posted August 11, 2019 Share Posted August 11, 2019 So I am trying to eliminate leading 0s on a string I have. Now there might be a better way to do this than my current method and I am open to those suggestions. However, I would still like to know what the current issue I am having is for learning sake. When I run the could without the Else > Exit Loop it runs through fine but removes more leading digits than needed because it counts extra 0s. With Else > Exit Loop the loop only runs one time no matter how many leading 0s I have. This is part of a much larger program but nothing else should be relevant. Value is the string containing whatever number I am entering, and I need it to remain a string. Quote $aString = StringSplit($Value, "", 2) For $Letter In $aString If $Letter = "0" Then $Value = StringTrimLeft($Value, 1) Else ExitLoop Next Link to comment Share on other sites More sharing options...
Developers Jos Posted August 11, 2019 Developers Share Posted August 11, 2019 There are multiple syntax errors in that If..Else. Open the Helpfile to see the proper syntax. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jchd Posted August 11, 2019 Share Posted August 11, 2019 Pick your choice: Local $a = "003.1415926" Local $b = StringRegExpReplace($a, "^0*", "") ConsoleWrite($b & @LF) Local $c = String(Number($a)) ConsoleWrite($c & @LF) 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...
StuckUser Posted August 11, 2019 Author Share Posted August 11, 2019 @Jos can you elaborate or give specifics? i had been using the help file. the only syntax i notice wrong is no EndIf, but I couldnt use that with ExitLoop. @jchd I had tried using other string replacers like yours that I had found but none seemed to work correctly, yours worked like a charm, THX! Link to comment Share on other sites More sharing options...
jchd Posted August 12, 2019 Share Posted August 12, 2019 Just a remark: if you can expect negative values, use that instead. Local $a = "-0003.1415926" Local $b = StringRegExpReplace($a, "^([-+])(0*)", "$1") ConsoleWrite($b & @LF) Conversion to Number() always work. 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...
Gianni Posted August 12, 2019 Share Posted August 12, 2019 (edited) if you prefer to keep a leading zero when a number is less than 1 you could also use this: Local $a = "-0000.31415926" $a = String($a * 1) ConsoleWrite($a & @LF) Edited August 12, 2019 by Chimp mikell 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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