Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:37:58+00:00 2026-06-11T17:37:58+00:00

I have a flag enumeration (int) mask, and I need to convert it to

  • 0

I have a flag enumeration (int) mask, and I need to convert it to a string representing the day of a Week.

say this is the FULL string and an arbitrary mask

strFullWeek = "MTWtFSs"
strWeekMask = "0100110"
-----------------------
strResult   = "-T--FS-"

what way would you propose to obtains strResult from full week and mask strings?

UPDATE

this is my “entire context” (VB.NET)

<Flags()> Public Enum Week
  Monday = 1
  Tuesday = 2
  Wednesday = 4
  Thursday = 8
  Friday = 16
  Saturday = 32
  Sunday = 64
End Enum

Dim mondayOrSunday = Week.Monday Or Week.Sunday
Dim strDays = "MTWtFSs"

Dim strMondayOrSundayBinary = Convert.ToString(
  mondayOrSunday, 2).PadRight(7, CChar("0"))

Dim charMondayOrSunday = strDays.Zip(
  strMondayOrSundayBinary,
  Function(day, mask) If(mask = CChar("1"), day, CChar("-"))).ToArray()

Dim strMondayOrSunday = New String(charMondayOrSunday)

Console.WriteLine("{0} I see as {1}",
                  mondayOrSunday,
                  strMondayOrSunday)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:00+00:00Added an answer on June 11, 2026 at 5:38 pm

    There’s a reasonably neat LINQ way:

    var chars = strFullWeek.Zip(strWeekMask, (day, mask) => mask == '1' ? day : '-'))
                           .ToArray();
    string text = new string(chars);
    

    It wouldn’t be terribly efficient, but it may be good enough…

    EDIT: Okay, assuming you’re happy with C# code for the enum version

    // TODO: Rename "Week" to comply with .NET naming conventions
    Week mask = Week.Monday | Week.Sunday;
    var chars = strFullWeek.Select((value, index) => (int) mask & (1 << index) != 0) 
                                                     ? value : '-')
                           .ToArray();
    string text = new string(chars);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very often when you code you have a flag indicating two possibilities, like this:
Take this scenario: You have a few flag enumerations in C# tied to (and
Using C# 3.0, .NET 3.5 I have a need for an enumeration that is
I have an enumeration with [Flag] attribute set on it. [Flags] public enum PageTags
How can I center the text in the image below I have this .flag{
I have an enumeration marked with a Flag attribute. How can I establish convenient
I have a table like: id(int) flag(int) price(float) 1 0 50 2 400 3
I'm using a shared host (fasthostingdirect) and for some reason they have this flag
Let's say I have an enumeration. enum class ShapeName : char {TRIANGLE,CIRCLE,SQUARE}; and later
I have a boolean flag :finished . Should I A: index({ finished: 1 })

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.