CSharp examples for System:String Search
Find a difference in two strings.
// This software is licensed under the LGPL, version 2.1 or later using System.Text; using System.Resources; using System.Linq; using System.IO;//from w w w .jav a 2 s .co m using System.Globalization; using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System; public class Main{ /// ------------------------------------------------------------------------------------ /// <summary> /// Find a difference in two strings. /// </summary> /// <param name="str1">first string to compare</param> /// <param name="str2">second string to compare</param> /// <param name="ichMin">the min of the difference that has already been found</param> /// <param name="ichLim1">The index of the limit of the difference in the 1st string</param> /// <param name="ichLim2">The index of the limit of the difference in the 2nd string</param> /// ------------------------------------------------------------------------------------ private static void FindStringDifferenceLimits(string str1, string str2, int ichMin, out int ichLim1, out int ichLim2) { ichLim1 = str1.Length; ichLim2 = str2.Length; // look backwards through the strings for the end of the difference. Do not // look past the start of the difference which has already been found. while (ichLim1 > ichMin && ichLim2 > ichMin) { if (str1[ichLim1 - 1] != str2[ichLim2 - 1]) return; --ichLim1; --ichLim2; } } }