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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:59:13+00:00 2026-05-30T03:59:13+00:00

How would I split a comma delimited string into smaller comma delimited strings? My

  • 0

How would I split a comma delimited string into smaller comma delimited strings?

My string looks like this: 1,2,3,4,5,6,7,8,9,10

And I need to split the string after every nth occurrence of the , character.
E.g. for every 3rd occurrence, the above string would be turned into these strings:
1,2,3,4 5,6,7,8 9,10

Might look like homework but it’s not, my brain is just tired but I still need to get work done.

  • 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-30T03:59:15+00:00Added an answer on May 30, 2026 at 3:59 am

    Try a loop in which you count the commas 😉

    Untested, it could look like:

    int lastSplit = 0;
    int commaCount = 0;
    int n = 4;
    List<string> parts = new List<string>();
    
    for (int i = 0; i < s.Length; i++)
    {
       if (s[i] == ',' && ++commaCount == n)
       {
          commaCount = 0;
          parts.Add(s.Substring(lastSplit, i - lastSplit));
          lastSplit = i + 1;
       }
    }
    
    parts.Add(s.Substring(lastSplit));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What regex pattern would need I to pass to java.lang.String.split() to split a String
I've got a comma delimited string of id's coming in and I need some
I'd like to String.Split() the following string using a comma as the delimitter: John,Smith,123
I have a stored procedure that takes a comma-delimited string of IDs. I split
I have a comma delimited CSV file being loaded into a String value generated
I'd like to split a comma separated value into pairs: >>> s = '0,1,2,3,4,5,6,7,8,9'
I'm using perl and need to split strings of author names delimited by commas
How would I split a HTML formatted file into several HTML files (complete with
I am writing many files to disk, and I would like to split them
I have a large source repository split across multiple projects. I would like 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.