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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:52:20+00:00 2026-05-25T14:52:20+00:00

Hi guys this is my first question ever on SO so please go easy

  • 0

Hi guys this is my first question ever on SO so please go easy on me.

I am playing with Lambda/LINQ while building myself few utility methods.

  1. First method takes string like,

    "AdnanRazaBhatti" 
    

    and breaks it up like ,

    "Adnan Raza Bhatti"
    
  2. Second Methods takes string like first method and also takes,

    out String[] brokenResults 
    

    and returns broken string like the first method as well as fill up brokenResults array as follows.

      "Adnan" "Raza" "Bhatti"
    

Questions:

A. Can you please suggest how to make these methods more efficient?

B. When I try to use StringBuilder it tells me extension methods like, Where, Select does not exist for StringBuilder class, why is it so? Although indexer works on StringBuilder to get the characters like StringBuilder s = new StrinBuilder(“Dang”); char c = s[0]; Here char will be D;

Code

Method 1:

  public static string SplitCapital( string source )
    {

        string result = "";
        int i = 0;
        //Separate all the Capital Letter
        var charUpper = source.Where( x => char.IsUpper( x ) ).ToArray<char>( );
        //If there is only one Capital letter then it is already atomic. 
        if ( charUpper.Count( ) > 1 ) {
            var strLower = source.Split( charUpper );
            foreach ( string s in strLower )
                if ( i < strLower.Count( ) - 1 && !String.IsNullOrEmpty( s ) )
                    result += charUpper.ElementAt( i++ ) + s + " ";
            return result;
        }
        return source;
    }

Method 2:

  public static string SplitCapital( string source, out string[] brokenResults )
    {
        string result = "";
        int i = 0;
        var strUpper = source.Where( x => char.IsUpper( x ) ).ToArray<char>( );

        if ( strUpper.Count( ) > 1 ) {
            var strLower = source.Split( strUpper );

            brokenResults = ( 
                from s in strLower
                where i < strLower.Count( ) - 1 && !String.IsNullOrEmpty( s )
                select result = strUpper.ElementAt( i++ ) + s + " " ).ToArray( );

            result = "";
            foreach ( string s in brokenResults )
                result += s;
            return result;
        }
        else { brokenResults = new string[] { source }; }
        return source;
    }

Note:

I am planning to use these utility methods to break up the table column names I get from my database.

For Example if column name is “BooksId” I will break it up using one of these methods as “Books Id” programmatically, I know there are other ways or renaming the column names like in design window or [dataset].[tableName].HeadersRow.Cells[0].Text = “Books Id” but I am also planning to use this method somewhere else in the future.

Thanks

  • 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-25T14:52:23+00:00Added an answer on May 25, 2026 at 2:52 pm

    you can use the following extension methods to split your string based on Capital letters:

    public static string Wordify(this string camelCaseWord)
        {
            /* CamelCaseWord will become Camel Case Word,  
              if the word is all upper, just return it*/
    
            if (!Regex.IsMatch(camelCaseWord, "[a-z]"))
                return camelCaseWord;
    
            return string.Join(" ", Regex.Split(camelCaseWord, @"(?<!^)(?=[A-Z])"));
        }
    

    To split a string in a string array, you can use this:

    public static string[] SplitOnVal(this string text,string value)
        {
            return text.Split(new[] { value }, StringSplitOptions.None);
        }
    

    If we take your example for consideration, the code will be as follows:

    string strTest = "AdnanRazaBhatti";
    var capitalCase = strTest.Wordify(); //Adnan Raza Bhatti
    var brokenResults = capitalCase.SplitOnVal(" ");  //seperate by a blank value in an array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys I know this question is very basic but I've met in few publications
Hey there guys, this is my first question on Stack Overflow. I figured this
First question on SOF, please be gentle if this may be a stupid question.
This is part observation, part question. First the observation: While everyone talks of modular
Hey guys. This is a very simple question, I'm sure, but I'm getting myself
As outlined by this guys post, blocking IP's via PHP is pretty easy. However,
So we are a few guys developing this product that is communicating with a
Guys I know this question is silly but just to make sure: Having in
Ok guys I imagine this is easy but I can't seem to find how
First of all, I'm sorry about the feedback-nature of this question. I'm trying to

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.