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 3275892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:11:43+00:00 2026-05-17T19:11:43+00:00

I am trying to transform a string made of words starting with an uppercase

  • 0

I am trying to transform a string made of words starting with an uppercase letter. I want to separate each word with a space and keep only the first uppercase letter. All other letters should be lowercase.

For example, “TheQuickBrownFox” would become “The quick brown fox”.

Obviously, I could use a simple foreach and build a string by checking each character, but I am trying to do it using LINQ.

Would you know how to solve this elegantly using LINQ?

Thank you for your help.

  • 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-17T19:11:43+00:00Added an answer on May 17, 2026 at 7:11 pm

    You can split the words using a regular expression (and little LINQ):

    public string SplitAsWords(string original)
    {
        var matches = Regex.Matches(original, "[A-Z][a-z]*").Cast<Match>();
        var str = string.Join(" ", matches.Select(match => match.Value));
        str = str[0] + str.Substring(1).ToLower();
        return str;
    }
    

    A usage example:

    [Test]
    public void Example()
    {
        string str = SplitAsWords("TheQuickBrownFox");
        Assert.That(str, Is.EqualTo("The quick brown fox"));
    }
    

    An alternative implementation using regular expression can be (with no LINQ):

    public string SplitAsWords(string original)
    {
        var str = Regex.Replace(original, "[a-z][A-Z]", 
            new MatchEvaluator(match => match.Value.ToLower().Insert(1, " ")));
    
        return str;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I am trying to transform my data.frame by calculating the log-differences of each column
In F# I want to transform a list of chars into a string. Consider
I am trying to write a function to transform a string literal in Delphi/pascal
I'm trying to generate this doctype string: <!DOCTYPE games SYSTEM transform.dtd> This is what
I have a problem trying to transform a given input string to a given
I'm trying to transform a hash definition which is stored in a string to
be gentle. I'm trying to use javax.xml.transform.Transformer to format some xml string to be
I am trying to transform a moving animated sprite to be a reverse of
I'm trying to transform one XML format to another using XSL. Try as I

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.