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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:02+00:00 2026-06-10T19:52:02+00:00

Im gone substring a description text after a certain count with .Substring(0, 100) .

  • 0

Im gone substring a description text after a certain count with .Substring(0, 100). I dont want to break in the middle of a word, if thats the case i would like to get to the first whitespace before the word.

I figure i check if the next character is not a " " its in the middle of the word.
My biggest issue is how do step backwards to get the index of the " " (whitespace).

this is what i got so far

        string description = "a long string";            

        description = Regex.Replace(description, @"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", String.Empty);
        var newString = (description.Count() > 101) ? description.Substring(0, 101) : description;

        //i tried something like this
        var whatIsNext = newString.IndexOf(" ", 100, -20);
  • 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-10T19:52:03+00:00Added an answer on June 10, 2026 at 7:52 pm

    I think you’re looking for String.LastIndexOf:

    Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string.

    You want something like this:

    int index = s.LastIndexOf(' ', 100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that contains two lines of numbers, all I want
Have gone through hibernate api specification on FlushMode but didn't get the exact difference.
I've gone through and made sure the memory usage is good on my app
I have gone through Google and Stack Overflow search, but nowhere I was able
I have gone through this to change the color of my title bar. I'm
I have gone through this page... http://www.php.net/manual/en/function.hash.php MD5 is 32 characters long while sha1
I've gone through many examples, questions and tutorials but I've never seen an activity
I have gone through a couple of similar questions but could reach a definite
I've gone through several questions and articles in the web and almost all of
I have gone through the fadein/fadeout tutorial that is on this page: For the

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.