WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bottomleypotts on July 01, 2021, 10:37:46 AM

Title: Weird behaviour
Post by: bottomleypotts on July 01, 2021, 10:37:46 AM
I have a problem with winbatch. It does not appear not all numbers in a string can be converted correctly.

See the messages the following code produces. Can someone explain why the last number in each line is not being recognized as a number and a way around it in the immediate interim?

Code (winbatch) Select

v=$"xxx,1,2
yyy,2,3
zzz,3,4$"

For i=1 to ItemCount(v,@LF)
   e=ItemExtract(i,v,@LF)

   a=Arrayize(e,`,`)

   m=``

   For j=0 to ArrInfo(a,1)-1
      m:=j:` `:IsNumber(a[j]):@CR
   Next j
   Message(i,m)
Next i
Title: Re: Weird behaviour
Post by: bottomleypotts on July 01, 2021, 10:54:21 AM
Just a follow up. Just noticed the extra space in the string before the @LF. Sigh!
Title: Re: Weird behaviour
Post by: kdmoyers on July 01, 2021, 11:06:52 AM
Yeah, when you use the multiline style strings (which are otherwise great) you get a surprising space at the end of each line.  It's no problem once you realize it's there. 

It's actually documented: "Note that when a script line is delimited by the carriage-return + line-feed combination, the carriage return is converted to a space and the line-feed character is retained."
Title: Re: Weird behaviour
Post by: td on July 01, 2021, 11:55:02 AM
Could be solved with this simple modfication

Code (winbatch) Select
m:=j:` `:IsNumber(strTrim(a[j])):@CR

But as Kirby mentioned the trick is knowing the space is there.

Title: Re: Weird behaviour
Post by: td on July 02, 2021, 07:31:51 AM
If you happen to use WinBatch Studio to create and edit your scripts, you can change the settings to use line-feed instead of carriage-return + line-feed as the line terminator in your scripts. Select the "View" top-level menu and then "Options..." -> "File Types" tab -> select "WIL Files" from the "File" dropdown -> select the "LF" radio button in the "Line end" group box -> press the "OK" button.

Using this technique you don't ever have to worry about the extra space as long as you use WinBatch Studio to create and edit your scripts.