0

I have a correct string and then a string come anywhere. I must compare but this strings maybe not equal. Example Correct string is

SAAT:23:34

Coming string

SAAT:12:23

When I compare this strings, Answer must be true.

Patern like this

SAAT:..:..
Regex.IsMatch(); 

give me t string but ı dont want to this.

How can I compare two string..

5
  • 5
    Insufficient data... Why is SAAT:23:34 equal to SAAT:12:23 ? Would it be equal to SAAT:xx:yy ? Or TAAS.12.23 ? Commented Jan 10, 2011 at 13:55
  • I want to discard some character. Exaple Date and Time values not important for me. Is Other chars equal? I want to know this. Commented Jan 10, 2011 at 13:56
  • 3
    Still not enough. Add another example and we've got an IQ test. Commented Jan 10, 2011 at 13:57
  • 2
    Please give to me an IQ test. Commented Jan 10, 2011 at 14:00
  • 2
    I think he was being clever and wanted you to write something like Sit is to Stand as Walk is to ___ (Run) or something like that. Keep hitting refresh I'm sure an Ad for an IQ test will pop eventually on the right. Commented Jan 10, 2011 at 14:09

1 Answer 1

2

Based on the information you've provided and my lack of caffeine here is a solution:

    static bool IsEqual(String left, String right)
    {
        left = Regex.Replace(left, ":[0-9]*:[0-9]*", "");
        right = Regex.Replace(right, ":[0-9]*:[0-9]*", "");
        return left.Equals(right);
    }

    static void Main(string[] args)
    {
        Console.WriteLine(IsEqual("SAAT:232:34", "SAAT:12:23")); // True
        Console.WriteLine(IsEqual("PAAT:23:34", "SAAT:12:23")); // False
        Console.WriteLine(IsEqual("SAAT:23:34:HAT", "SAAT:12:23:HAT")); // True
    }
Sign up to request clarification or add additional context in comments.

2 Comments

@Murat No problem. I don't really like the double String replace and was working on other solutions, but if this suites your needs I think I'll move on for now. Good luck.
This solution is enough for me for now. Thanks again. But you have a smart solution, ı want to see it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.