Jump to content

For Loop Exit Issue


Recommended Posts

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

  • Developers

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

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 here
RegExp tutorial: enough to get started
PCRE 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

@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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...