Advertisement
kyrathasoft

test if two strings have matching first chars ignoring case

May 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public static int MatchingBeginningCharactersInTwoStringsIgnoringCase(string _string1, string _string2){
  2. int matching = 0;
  3. int numCharToCompare = 0;
  4. string first = _string1.ToLower();
  5. string two = _string2.ToLower();
  6. char[] firstArray = first.ToCharArray();
  7. char[] secondArray = two.ToCharArray();
  8. if(first.Length > two.Length){
  9. numCharToCompare = two.Length;
  10. }else{
  11. numCharToCompare = first.Length;
  12. }
  13. for(int i=0; i < numCharToCompare; i++){
  14. if(firstArray[i] == secondArray[i]){ matching++;}
  15. }
  16. return matching;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement