比较字符串,并得到他们的海誓山盟改变首位 [英] Comparing strings and get the first place where they vary from eachother
本文介绍了比较字符串,并得到他们的海誓山盟改变首位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要得到的第一个地方,2串彼此不同。
例如:这两个字符串
:
AAAB
AAAAC
I want to get the first place where 2 string vary from each other. example: for these two strings: "AAAB" "AAAAC"
我想要得到的结果4。
我怎么做它在C#?
推荐答案
.NET 4:
string a1 = "AAAB";
string a2 = "AAAAC";
int index = a1.Zip(a2, (c1, c2) => c1 == c2).TakeWhile(b => b).Count() + 1;
这篇关于比较字符串,并得到他们的海誓山盟改变首位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文