How to operate with variables and conditions?

Questions & Answers about Helium Scraper 3
Post Reply
atibati
Posts: 2
Joined: Thu Oct 08, 2020 10:25 pm

How to operate with variables and conditions?

Post by atibati » Thu Oct 08, 2020 10:27 pm

Sometimes it's needed to change variable that is number to variable that is string. And sometimes any variable to boolean.

I've tried this construction

Code: Select all

if
   ·  Core.ToBoolean
         ·  result
   ·  [ifTrue]
   ·  [ifFalse]
, but it appears with execution failed when the variable result is not empty string.
- i need something to convert strings into false when it's empty string or void, but into true, when it's not empty string.

webmaster
Site Admin
Posts: 521
Joined: Mon Dec 06, 2010 8:39 am
Contact:

Re: How to operate with variables and conditions?

Post by webmaster » Fri Oct 09, 2020 5:59 pm

Core.ToBoolean just parses a "true" or "false" value into a boolean, so it won't work with empty strings. But you can write your own function using String.IsMatch and the negation operator. The following will return false when the string is empty and true when not:

Code: Select all

function (text)
   not
      ·  String.IsMatch
            ·  "^$"
            ·  text
And this will return false when the string is empty or whitespace, and true when not:

Code: Select all

function (text)
   not
      ·  String.IsMatch
            ·  "^\\s*$"
            ·  text
If you put any of those functions in a global (say you call it StringHasValue), you can then use it like:

Code: Select all

if
   ·  StringHasValue
         ·  result
   ·  [ifTrue]
   ·  [ifFalse]
Juan Soldi
The Helium Scraper Team

atibati
Posts: 2
Joined: Thu Oct 08, 2020 10:25 pm

Re: How to operate with variables and conditions?

Post by atibati » Sat Oct 10, 2020 1:23 am

Thank you. Work fine. But spend around 3 hours on finding and fixing a bug associated with this code. Also edited one of premades - chenged Sequence.First to Sequence.FirstOrDefault, and now it works fine.

Would be happy to be able add variables into code directly and print variables like function Alert in javascript (btw, i'm not js programer), for faster debug.

Post Reply