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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:04:34+00:00 2026-05-27T12:04:34+00:00

Is there an exsting string comparison method that will return a value based on

  • 0

Is there an exsting string comparison method that will return a value based on the first occurance of a non matching character between two strings?

i.e.

string A = "1234567890"

string B = "1234567880"

I would like to get a value back that would allow me to see that the first occurance of a matching break is A[8]

  • 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-27T12:04:35+00:00Added an answer on May 27, 2026 at 12:04 pm
    /// <summary>
    /// Gets a first different char occurence index
    /// </summary>
    /// <param name="a">First string</param>
    /// <param name="b">Second string</param>
    /// <param name="handleLengthDifference">
    /// If true will return index of first occurence even strings are of different length
    /// and same-length parts are equals otherwise -1
    /// </param>
    /// <returns>
    /// Returns first difference index or -1 if no difference is found
    /// </returns>
    public int GetFirstBreakIndex(string a, string b, bool handleLengthDifference)
    {
        int equalsReturnCode = -1;
        if (String.IsNullOrEmpty(a) || String.IsNullOrEmpty(b))
        {
            return handleLengthDifference ? 0 : equalsReturnCode;
        }
    
        string longest = b.Length > a.Length ? b : a;
        string shorten = b.Length > a.Length ? a : b;    
        for (int i = 0; i < shorten.Length; i++)
        {
            if (shorten[i] != longest[i])
            {
                return i;
            }
        }
    
        // Handles cases when length is different (a="1234", b="123")
        // index=3 would be returned for this case
        // If you do not need such behaviour - just remove this
        if (handleLengthDifference && a.Length != b.Length)
        {
            return shorten.Length;
        }
    
        return equalsReturnCode;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an existing PL/SQL method which takes a string and returns the same
Is there a quick way ( existing method) Concatenate array element into string with
Are there any existing libraries in existence that will parse a datetime from a
Seeking a method to: Take whitespace separated tokens in a String; return a suggested
Is there an existing library that allows me to annotate a Java method as
i have a string which is a return value of REST API ( http://requesttracker.wikia.com/wiki/REST
Is there an existing class in C# that can convert Quoted-Printable encoding to String
Is there existing software for discriminative reranking, such as that used by the Charniak
Is there an existing application or library in Java which will allow me to
I have a model that has several properties. The properties can be primitive (String)

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.