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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:32:43+00:00 2026-05-16T12:32:43+00:00

I saw this question that asks given a string smith;rodgers;McCalne how can you produce

  • 0

I saw this question that asks given a string “smith;rodgers;McCalne” how can you produce a collection. The answer to this was to use String.Split.

If we don’t have Split() built in what do you do instead?

Update:

I admit writing a split function is fairly easy. Below is what I would’ve wrote. Loop through the string using IndexOf and extract using Substring.

string s = "smith;rodgers;McCalne";

string seperator = ";";
int currentPosition = 0;
int lastPosition = 0;

List<string> values = new List<string>();

do
{
    currentPosition = s.IndexOf(seperator, currentPosition + 1);
    if (currentPosition == -1)
        currentPosition = s.Length;

    values.Add(s.Substring(lastPosition, currentPosition - lastPosition));

    lastPosition = currentPosition+1;

} while (currentPosition < s.Length);

I took a peek at SSCLI implementation and its similar to the above except it handles way more use cases and it uses an unsafe method to determine the indexes of the separators before doing the substring extraction.

Others have suggested the following.

  1. An Extension Method that uses an Iterator Block
  2. Regex suggestion (no implementation)
  3. Linq Aggregate method

Is this it?

  • 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-16T12:32:44+00:00Added an answer on May 16, 2026 at 12:32 pm

    It’s reasonably simple to write your own Split equivalent.

    Here’s a quick example, although in reality you’d probably want to create some overloads for more flexibility. (Well, in reality you’d just use the framework’s built-in Split methods!)

    string foo = "smith;rodgers;McCalne";
    foreach (string bar in foo.Split2(";"))
    {
        Console.WriteLine(bar);
    }
    
    // ...
    
    public static class StringExtensions
    {
        public static IEnumerable<string> Split2(this string source, string delim)
        {
            // argument null checking etc omitted for brevity
    
            int oldIndex = 0, newIndex;
            while ((newIndex = source.IndexOf(delim, oldIndex)) != -1)
            {
                yield return source.Substring(oldIndex, newIndex - oldIndex);
                oldIndex = newIndex + delim.Length;
            }
            yield return source.Substring(oldIndex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I saw an answer in another question saying that this should work: using
Let me preface by saying that I saw this other question on the subject
After reading this question , i saw the answer by Naveen containing a link
So I saw this post which helped answer part of my question however now
I saw some code yesterday in this question that I had not seen before,
I saw this question in a forum about how an application can be developed
I saw this question: how to save tags(keywords) in database? Good answer for how
I saw that this question has been asked the other way around, well my
I saw this question on a forum: http://www.geeksforgeeks.org/archives/19042 Given an undirected graph and a
I saw this question (http://stackoverflow.com/questions/1521640/standard-android-button-with-a-different-color) and that works fine for normal buttons. Now 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.