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

  • Home
  • SEARCH
  • 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 6745043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:25+00:00 2026-05-26T12:09:25+00:00

Given: A string dayCodes (i.e. MWF or MRFU ) that I need to split

  • 0

Given:

A string dayCodes (i.e. "MWF" or "MRFU") that I need to split and create a collection of strings so I can have a list of day of the week strings (i.e. "Monday", "Wednesday", "Friday" or "Monday", "Thursday", "Friday", "Sunday").

// this causes a run-time exception because you can't cast Char to String
var daysArray = days.ToCharArray().Cast<string>().ToArray();

// for each dayCode, overwrite the code with the day string.
for (var i = 0; i < daysArray.Length; i++)
{
    switch (daysArray[i])
    {
        case "M":
            daysArray[i] = "Monday";
            break;

        case "T":
            daysArray[i] = "Tuesday";
            break;

        case "W":
            daysArray[i] = "Wednesday";
            break;

        case "R":
            daysArray[i] = "Thursday";
            break;

        case "F":
            daysArray[i] = "Friday";
            break;

        case "S":
            daysArray[i] = "Saturday";
            break;

        case "U":
            daysArray[i] = "Sunday";
            break;
    }
 }

 daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1];

 return string.Join(", ", daysArray);

Problem:

The problem is that you can’t cast Char to String which I guess makes sense because one is not inherited from the other. Still you’d think that the compiler would cast the Char as a one character long String.

Is there a quick way (like using Cast<string>()) to do this so I don’t have to create a List<string> from scratch?

  • 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-05-26T12:09:25+00:00Added an answer on May 26, 2026 at 12:09 pm

    Just using char.ToString() would work:

    var daysArray = days.ToCharArray().Select( c => c.ToString()).ToArray();
    

    Alternatively, and a better solution in my mind why don’t you use the string directly with a dictionary for the mapping:

    var daysArray = days.Select( c => dayMapping[c]).ToArray();
    

    with dayMapping just a Dictionary<char, string> that maps to the full day name:

    Dictionary<char, string> dayMapping = new Dictionary<char,string>()
    {
        {  'M', "Monday" },
        {  'T', "Tuesday" }
        //and so on
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built-in function/method that can check if a given string is a
What regular expression can I use (if any) to validate that a given string
Given a string of a mobile phone number, I need to make sure that
I want to split the given string and remove the duplicate from that string.
I need a function that returns whether the given string contains at least x
I need a regular expression that detects if a given string is a url
I have a filename in a string. I want to split the given string
How can I drop all tables whose names begin with a given string? I
I have a requirement to disallow backslash characters in a given string field defined
I've been looking for a way to hash a given string in C# that

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.