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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:24:19+00:00 2026-05-25T20:24:19+00:00

The messages are exact dont need to worry about variation or simbols in between,

  • 0

The messages are exact dont need to worry about variation or simbols in between, right now I am just looking for a efficient way that can check messages like the below.

I have a message like:

string msg = "This is a small message !";

And I would like to check if that message was sent repeated times in the same string like this:

string msg = "This is a small message !This is a small message !";

or:

string msg = "This is a small message !This is a small message !This is a small message !";

or:

string msg = "This is a small message !This is a small message !This is a small message !This is a small message !This is a small message !";

I have a LinkedList<string> that stores the last 3 messages received and along with those last 3 message I would like to match the current messages to see if it is either equal to one of the current store messages or a repetition of any.

foreach (string item in myListOfMessages)
{
    if (string.Equals(msg, item))
    {
        // the message matchs one of the stored messages
    }
    else if (msg.Lenght == (item.Lenght * 2) && string.Equals(msg, string.Concat(item, "", item)))
    {
        // the message is a repetition, and ofc only works when some one sends the message twice in the same string
    }
}

Like I showed in the examples, the repetition could be quite large, also I am not sure if the method I presented above is the best one for what I need. It was the first idea that came to my mind but soon after I realised that it would produce a lot more work that way.

  • 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-25T20:24:20+00:00Added an answer on May 25, 2026 at 8:24 pm

    Linq to the rescue:

    string msg = "This is a small message !";
    string otherMsg = "This is a small message !This is a small message !This is a small message !This is a small message !This is a small message !";
    
    bool isRepeated = Enumerable.Range(0, otherMsg.Length / msg.Length)
                                .Select(i => otherMsg.Substring(i *  msg.Length,  msg.Length))
                                .All( x => x == msg);
    

    This approach basically takes a sub string of the length of the first message and compares each chunk with the original message.

    Wrapped in a method with some pre-checking:

    public bool IsRepeated(string msg, string otherMsg)
    {
        if (otherMsg.Length < msg.Length || otherMsg.Length % msg.Length != 0)
            return false;
    
        bool isRepeated = Enumerable.Range(0, otherMsg.Length / msg.Length)
                                    .Select(i => otherMsg.Substring(i * msg.Length, msg.Length))
                                    .All(x => x == msg);
        return isRepeated;
    }
    

    Edit:

    Above approach will generate unnecessary strings that will have to be gc’ed – a much more efficient and faster solution:

    public bool IsRepeated(string msg, string otherMsg)
    {
        if (otherMsg.Length < msg.Length || otherMsg.Length % msg.Length != 0)
            return false;
    
        for (int i = 0; i < otherMsg.Length; i++)
        {
            if (otherMsg[i] != msg[i % msg.Length])
                return false;
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my logging messages, I need to insert the name of the method where
The exact exception message would be helpful, too. Thanks.
I'm getting a bunch of failing tests (21 to be exact)/ an error message
I've stored individual messages as .eml files on my disk. When it comes time
I'm storing messages from an amazon cloud and ordering them by their timestamp in
I'm getting error messages for no reason in RAD 8: And the error message
I want to broadcast messages locally to many application. For that I thought UDP
I have Messages and User models with corresponding tables. The Messages table has such
I receive messages from a Google Talk account, they are shown in the Table
I have table messages | id | user_id | recepient_id | message | 1

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.