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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:32:24+00:00 2026-06-14T07:32:24+00:00

How do I get the first 250 words of a string?

  • 0

How do I get the first 250 words of a string?

  • 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-14T07:32:26+00:00Added an answer on June 14, 2026 at 7:32 am

    You need to split the string. You can use the overload without parameter(whitespaces are assumed).

    IEnumerable<string> words = str.Split().Take(250);
    

    Note that you need to add using System.Linq for Enumerable.Take.

    You can use ToList() or ToArray() ro create a new collection from the query or save memory and enumerate it directly:

    foreach(string word in words)
        Console.WriteLine(word);
    

    Update

    Since it seems to be quite popular I’m adding following extension which is more efficient than the Enumerable.Take approach and also returns a collection instead of the (deferred executed) query.

    It uses String.Split where white-space characters are assumed to be the delimiters if the separator parameter is null or contains no characters. But the method also allows to pass different delimiters:

    public static string[] GetWords(
           this string input,
           int count = -1,
           string[] wordDelimiter = null,
           StringSplitOptions options = StringSplitOptions.None)
    {
        if (string.IsNullOrEmpty(input)) return new string[] { };
    
        if(count < 0)
            return input.Split(wordDelimiter, options);
    
        string[] words = input.Split(wordDelimiter, count + 1, options);
        if (words.Length <= count)
            return words;   // not so many words found
    
        // remove last "word" since that contains the rest of the string
        Array.Resize(ref words, words.Length - 1);
    
        return words;
    }
    

    It can be used easily:

    string str = "A B C   D E F";
    string[] words = str.GetWords(5, null, StringSplitOptions.RemoveEmptyEntries); // A,B,C,D,E
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to get first n words from text stored in my database without
Is there anyways to get first two element of each profile_id using php array(
How can I get first and last days of the current week? What I
I want to get first and last name of a google account using gdata
Normally, we get first value that way: $(#color option:first).val() But I need something like
How to get the first child id inside the div using JQuery. Sample code:
I need to get the first and last dimension of an numpy.ndarray of arbitrary
I'm trying to get the first paragraph height within a div and store it
I am trying to get the first word in the line that matches the
I would like to get the first item from a list matching a condition.

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.