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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:59:18+00:00 2026-05-25T22:59:18+00:00

Is there any method that I can use that returns a fixed length array

  • 0

Is there any method that I can use that returns a fixed length array after spliting a string with some delimiter and fill the rest with a default string.
Eg.

string fullName = "Jhon Doe";
string[] names = fullName.SpecialSplit(some parameters); //This should always return string array of length 3 with the second elememnt set to empty if there is no middle name.
  • 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-25T22:59:19+00:00Added an answer on May 25, 2026 at 10:59 pm

    You should read over Jon Skeet’s Writing the perfect question. It will be beneficial to you in the future when posting questions of StackOverflow.

    There is no method in C# to do what you are asking, but you can easily write an extension method to do what I think you are asking.

    here is a quick example:

    public static class AbreviatorExtention
        {
    
            public static string[] GetInitials(this String str, char splitChar)
            {
                string[] initialArray = new string[3];
                var nameArray = str.Split(new char[] { splitChar },
                                StringSplitOptions.RemoveEmptyEntries);
    
                if (nameArray.Length == 2)
                {
                    var charArrayFirstName = nameArray[0].ToCharArray();
                    var charArrayLastName = nameArray[1].ToCharArray();
    
                    initialArray[0] = charArrayFirstName[0].ToString().ToUpper();
                    initialArray[1] = string.Empty;
                    initialArray[2] = charArrayLastName[0].ToString().ToUpper();
                }
                else
                {
                    for (int i = 0; i < nameArray.Length; i++)
                    {
                        initialArray[i] = (nameArray[i].ToCharArray())[1]
                                          .ToString().ToUpper();
                    }
                }
    
    
                return initialArray;
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                string FullName = "john doe";
    
                //Extension method in use
                string[] names = FullName.GetInitials(' ');
    
                foreach (var item in names)
                {
                    Console.WriteLine(item); 
                }
    
                Console.ReadLine();
            }
        }
    

    Output:

    J
    
    D
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose
In Ruby is there any method that lists all the global variables available at
There is any command line or .NET method that runs a process in the
I have searched through internet & found that there are no any direct method
Is there any method? My computer is AMD64. ::std::string str; BOOL loadU(const wchar_t* lpszPathName,
Is there any method to generate MD5 hash of a string in Java?
In a C++ application that can use just about any relational database, what would
How can I define that method returns List[+AnyRef]? I tried: def a[T <: AnyRef]():
Out of curiosity...what happens when we call a method that returns some value but
I am testing a static method that builds a URL string after checking proxies

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.