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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:03:07+00:00 2026-06-17T15:03:07+00:00

My goal is to run through a database of strings and get the count

  • 0

My goal is to run through a database of strings and get the count each time each substring occurs. In other words I need to extract all possible word combinations from the string.

For example the input might be "this is the first string".

I would want to extract "this is", "is the", "the first", "first string", "this is the", "is the first", "the first string", "this is the first", "is the first string".

I only need to go left to right, always in order.

I am not really sure where to start with this. I already have the code to read database and save into list, just need to know how to extract all possible sub strings based on the space character.

  • 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-17T15:03:08+00:00Added an answer on June 17, 2026 at 3:03 pm

    The following method builds up a list of the indices of all spaces in your string (plus notional start and end spaces), then returns the substring between every ordered pair of indices:

    static IEnumerable<string> SpaceDelimitedSubstrings(string input)
    {
        List<int> indices = new List<int> { -1 };
        int current = -1;
        while ((current = input.IndexOf(' ', current + 1)) > -1)
        {
            indices.Add(current);
        }
        indices.Add(input.Length);
    
        int minLength = 1;
        for (int i = 0; i < indices.Count - minLength; i++)
            for (int j = i + minLength; j < indices.Count; j++)
                yield return input.Substring(indices[i] + 1, indices[j] - indices[i] - 1);
    }
    

    Called as follows

    string input = "this is the first string";
    foreach (var s in SpaceDelimitedSubstrings(input))
    {
        Console.WriteLine(s);
    }
    

    it gives

    this

    Changing minLength to 2 will cut out the single-word returns.

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

Sidebar

Related Questions

The goal: Connect to database using php to extract results Loop through results Store
I have maven-plagin and need to run goal, that should automatically run before plugin.
The goal: run some functions on .ajaxStart() but only if fired by a certain
We're using the Maven exec:java goal to run a custom java application that configures
I'm trying to run exec-maven-plugin 's exec:java goal on a simple two-module project where
My final goal is to write the program which can run on the Unix
I'm looping through an array, and during each iteration of the loop, I'm calling
I have two arraylists, one contains Strings and the other contains Classes that have
I've been trying to run a file through a shell script and write its
My goal is to run flash locally on a Windows Surface RT tablet. From

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.