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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:24:37+00:00 2026-05-21T16:24:37+00:00

This question is not related to: Best way to break long strings in C#

  • 0

This question is not related to:

Best way to break long strings in C# source code

Which is about source, this is about processing long outputs. If someone enters:

WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

As a comment, it breaks the container and makes the entire page really wide. Is there any clever regexp that can say, define a maximum word length of 20 chars and then force a whitespace character?

Thanks for any help!

  • 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-21T16:24:37+00:00Added an answer on May 21, 2026 at 4:24 pm

    There’s probably no need to involve regexes in something this simple. Take this extension method:

    public static string Abbreviate(this string text, int length) {
        if (text.Length <= length) {
            return text;
        }
    
        char[] delimiters = new char[] { ' ', '.', ',', ':', ';' };
        int index = text.LastIndexOfAny(delimiters, length - 3);
    
        if (index > (length / 2)) {
            return text.Substring(0, index) + "...";
        }
        else {
            return text.Substring(0, length - 3) + "...";
        }
    }
    

    If the string is short enough, it’s returned as-is. Otherwise, if a “word boundary” is found in the second half of the string, it’s “gracefully” cut off at that point. If not, it’s cut off the hard way at just under the desired length.

    If the string is cut off at all, an ellipsis (“…”) is appended to it.

    If you expect the string to contain non-natural-language constructs (such as URLs) you ‘d need to tweak this to ensure nice behavior in all circumstances. In that case working with a regex might be better.

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

Sidebar

Related Questions

This is a not related to my project code , but a question came
First of all: This question is not directly programming related. However, the problem only
I have seen many answers for this type of question but its not related
This question is related to Java Refuses To Start - Could Not Resrve Enough
This is a general question, not related to a particular operation. I would like
This question is not technical, but is still about programming. What is the funniest,
This question is not about caching. I need this in-memory table for many small
First, I'm not sure if I should break this question into smaller, individual questions.
This might not be a hard core programming question, but it's related to some
This is related to my previous question about selecting visible elements . Now, here's

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.