Search code examples
c#arraysvb.netbooleandayofweek

How to Convert Bit String to Boolean Array


In VB or C#, is there a concise way (no looping) to convert a string to a boolean array? I have a string of binary values representing days of the week ("0001100") and wish to convert to a boolean array (false, false, false, true, true, false, false).


Solution

  • No, there is no built in method for turning a string into a boolean array.

    You have to do that by looping the characters in the string and check each one for the value, but you can easily do that with the Select method:

    bool[] days = daysString.Select(c => c == '1').ToArray();