Author Topic: setting a bool val from a string  (Read 2167 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
setting a bool val from a string
« on: August 19, 2011, 08:29:16 pm »
probably a stupid question but all the easier to answer

can i set a boolean value from a string value? say if the string was 'false'?

im currently rewriting that birds nest that is my shop script, im sure you all remember that one
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Shoozza

  • Retired Soldat Developer
  • Veteran
  • ******
  • Posts: 1632
  • Soldat's Babysitter
    • Website
Re: setting a bool val from a string
« Reply #1 on: August 20, 2011, 03:42:33 am »
Not sure if this works with soldatserver scripting but it works with Delphi.

boolvalue := LowerCase(stringvalue) = 'true';
Rules
Tools: ARSSE - SARS - SRB - chatMod

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: setting a bool val from a string
« Reply #2 on: August 20, 2011, 06:03:41 am »
if text = "true" then boolvar := true else boolvar := false; ?

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: setting a bool val from a string
« Reply #3 on: August 20, 2011, 08:32:37 am »
I don't know if this function exists (I think it did at one point), but in any case it can be easily made: function StrtoBool(str: string): boolean;. What others have said should suffice, depending on your application may be more, or less convenient.

@dnmr: keep in mind to use single ('), not double (") quotes.

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: setting a bool val from a string
« Reply #4 on: August 20, 2011, 01:14:54 pm »
Code: [Select]
StrToBool(str: string): boolean;
begin
  case lowercase(str) of
    'yes', 'true', 'on', '1', 'enabled': result := true;
    else result := false;
  end;
end;

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: setting a bool val from a string
« Reply #5 on: August 20, 2011, 03:04:11 pm »
@dnmr: keep in mind to use single ('), not double (") quotes.
your shoelaces are untied D:

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: setting a bool val from a string
« Reply #6 on: August 21, 2011, 10:36:16 am »
boolvalue := (LowerCase(stringvalue) = 'true');
Parentheses to make sure. Looks the most sexy imo. Also, that LowerCase() is quite optional.