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

  • Home
  • SEARCH
  • 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 8212687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:50:40+00:00 2026-06-07T10:50:40+00:00

I have a large string accepted from TCP listner which is in following format

  • 0

I have a large string accepted from TCP listner which is in following format

“1,7620257787,0123456789,99,0922337203,9223372036,32.5455,87,12.7857,1/1/2012,9223372036:1,7620257787,0123456789,99,0922337203,9223372036,32.5455,87,12.7857:2/1/2012,234234234:3,7620257787,01234343456789,99,0922337203,9223372036,32.5455,87,12.7857,1/1/2012,9223372036:34,76202343457787,012434343456789,93339,34340922337203,9223372036,32.5455,87,12.7857,1/1/2012,9223372036”

You can see that this is a : seperated string which contains Records which are comma seperated fields.

I am looking for the best (fastest) way that split the string in given number of chunks and take care that one chunk should contain full record (string upto ‘:’)

or other way of saying , there should not be any chunck which is not ending with :

e.g. 20 MB string to 4 chunks of 5 MB each with proper records (thus size of each chunk may not be exactly 5 MB but very near to it and total of all 4 chunks will be 20 MB)

I hope you can understand my question (sorry for the bad english)

I like the following link , but it does not take care of full record while spliting also don’t know if that is the best and fastest way.

Split String into smaller Strings by length variable

  • 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-06-07T10:50:41+00:00Added an answer on June 7, 2026 at 10:50 am

    The idea is to divide the lenght of your data for the num of blocks required, then look backwards to search the last sep in the current block.

        private string[] splitToBlocks(string data, int numBlocks, char sep)
        {
            // We return an array of the request length
            if (numBlocks <= 1 || data.Length == 0)
            {
                return new string [] { data };
            }
    
            string[] result = new string[numBlocks];
    
            // The optimal size of each block
            int blockLen = (data.Length / numBlocks);
    
            int idx = 0; int pos = 0; int lastSepPos = blockLen;
            while (idx < numBlocks)
            {
                // Search backwards for the first sep starting from the lastSepPos
                char c = data[lastSepPos];
                while (c != sep) { lastSepPos--; c = data[lastSepPos]; }
    
                // Get the block data in the result array
                result[idx] = data.Substring(pos, (lastSepPos + 1) - pos);
    
                // Reposition for then next block
                idx++;
                pos = lastSepPos + 1;
    
                if(idx == numBlocks-1)
                    lastSepPos = data.Length - 1;
                else
                    lastSepPos = blockLen * (idx + 1);
            }
            return result;
        }
    

    Please test it. I have not fully tested for fringe cases.

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

Sidebar

Related Questions

I have a large string in the following format - <a href=12345.html><a href=12345.html><a href=12345.html><a
I have a arbitrarily large string of text from the user that needs to
I have a large string variable that is assigned from a database column of
I have a significantly large string that that I need to format so that
I have a large String and I need to extract String value from it.
I have a large string and it might have the following: <div id=Specs class=plinks>
I have a large string which need be replaced a few times. Such as
I have one large string which goes like this: $string = '<span id=nothread307693965>blabla here
I have a large constant html string which I'd like to display on my
I have a large string which is a collection of key (space)+ value ,

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.