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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:58:34+00:00 2026-05-31T16:58:34+00:00

I have a string that needs to be chopped up. I’d like to do

  • 0

I have a string that needs to be chopped up. I’d like to do this in LINQ.
The string can have up to 32 letters.
I’d like to collect the parts in a dictionary.

The 1st part needs to have the first 4 letters. 
The 2nd part needs to have the first 5 letters. 
The 3rd part needs to have the first 6 letters. 
etc.

The key of the dictionary is simply a counter. I don’t know the length of the string, the min. length is 4.
How would I do this createively in LINQ?

  • 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-31T16:58:36+00:00Added an answer on May 31, 2026 at 4:58 pm

    You could make it an extension:

    public static Dictionary<int, String> Chop(this string str, int minLength)
    {
        if (str == null) throw new ArgumentException("str");
        if (str.Length < minLength) throw new ArgumentException("Length of string less than minLength", "minLength");
        var dict = str.TakeWhile((c, index) => index <= str.Length - minLength)
            .Select((c, index) => new { 
                Index = index, 
                Value = str.Substring(0, minLength + index) 
            }).ToDictionary(obj => obj.Index, obj => obj.Value);
    
        return dict;
    }
    

    Call it in this way:

    Dictionary<int, String> = "Insert sample string here".Chop(4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this that I need to parse into a 2D
I have a string that looks like this: [1011000, 1000010, 1001101, 1000011]. My argument
I have string like &amp;auml;s&amp;aring; that needs to be converted like äså so how
I have a string that like $input = '%name (%postcode) <%email>'; How can I
I have a string that holds user input. This string can contain various types
I have a piece of C# code that needs to convert a string array
I have a arbitrarily large string of text from the user that needs to
I have a string that needs to be validated. The first two characters must
I have a string in my cocoa GUI that needs to have special formatting
I have a text string that needs to become a DateTime object: Feb 10,

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.