viewpoint-particle

Author Topic: Weird behaviour  (Read 243 times)

bottomleypotts

  • Newbie
  • *
  • Posts: 42
Weird behaviour
« 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
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
 

bottomleypotts

  • Newbie
  • *
  • Posts: 42
Re: Weird behaviour
« Reply #1 on: July 01, 2021, 10:54:21 am »
Just a follow up. Just noticed the extra space in the string before the @LF. Sigh!

kdmoyers

  • Sr. Member
  • ****
  • Posts: 448
Re: Weird behaviour
« Reply #2 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."
The mind is everything; What you think, you become.

td

  • Tech Support
  • *****
  • Posts: 3992
    • WinBatch
Re: Weird behaviour
« Reply #3 on: July 01, 2021, 11:55:02 am »
Could be solved with this simple modfication

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

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

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3992
    • WinBatch
Re: Weird behaviour
« Reply #4 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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade