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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:42:55+00:00 2026-05-19T11:42:55+00:00

I am building a forum and it is in beta right now. The users

  • 0

I am building a forum and it is in beta right now. The users have begun to exploit certain things, like posting long strings of text with no spaces that will stretch the screen and ruin some styling. I just started using this code and it works fine.

        int charIndex = 0;
        int noSpaceCount = 0;
        foreach (char c in text.ToCharArray())
        {
            if (c != ' ')
                noSpaceCount++;
            else
                noSpaceCount = 0;

            if (noSpaceCount > 150)
            {
                text = text.Insert(charIndex, " ");
                noSpaceCount = 0;
            }
            charIndex++;
        }

This code works but I’d prefer a regular expression if possible. The problem is that I will be using regular expressions to identify links and I don’t want to break long links with a space as those will be fixed by making the link display text abbreviated. So I don’t want to insert a space into a piece of text that identifies as a URL, but I do want to insert a space every 150 characters of unbroken, non-link, text.

Any suggestions?

  • 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-19T11:42:56+00:00Added an answer on May 19, 2026 at 11:42 am

    This was surprisingly complicated. Thank Eric and colleagues for the great .NET regex library.

    resultString = Regex.Replace(subjectString, 
        @"(?<=     # Assert that the current position follows...
         \s        # a whitespace character
         |         # or
         ^         # the start of the string
         |         # or
         \G        # the end of the previous match.
        )          # End of lookbehind assertion
        (?!(?:ht|f)tps?://|www\.)  # Assert that we're not at the start of a URL.
        (\S{150})  # Match 150 characters, capture them.", 
        "$1 ", RegexOptions.IgnorePatternWhitespace);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a forum. Now I would like to create a query that returns
I am building a forum type site whereby the users will have an avatar.
im building a forum and now im gonna code the thread page. is there
I'm building a simple web based forum application. I want to allow users to
I'm building a forum for my friends to use, but since we have been
I am building a forum from scratch in PHP. I have used the most
I'm building a forum that will allow users to upload images. Images will be
Basically I am building an auto Awards system for users of my forum. What
I am building a system where the user can search users in a forum
I am building a forum and I have two tables: Threads ------- ThreadID UsersID

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.