c# 求提供思路,我str1“i want to eat an apple” str2"i want eat apple

c# 求提供思路,我str1“i want to eat an apple” str2"i want eat apple"用什么方法可以识别出str2少了
to 和an两个单词
古色紫檀 1年前 已收到1个回答 举报

懦弱的狮子 幼苗

共回答了16个问题采纳率:100% 举报

string str1="i want to eat an apple";
string str2="i want eat apple";
Console.WriteLine(str1.Length);
Console.Write(str2.Length);
Console.ReadKey();
第一个长度是22
第二个是16.
str2不就少了吗?

1年前 追问

1

古色紫檀 举报

谢谢,那我怎么知道少了什么呢。。。

举报 懦弱的狮子

string[] aa; string[] bb; string str1="i want to eat an apple"; string str2="i want eat apple"; aa = str1.Split(' '); bb = str2.Split(' '); int count=0; foreach(string c in aa) { count = 0; for (int i = 0; i < bb.Length; i++) { if (c != bb[i]) { count++; } if (count == bb.Length) { Console.Write(c+' '); } } } Console.ReadKey(); 已经把to和an两个缺失的单词在控制台输出了。你拿去用吧。
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.024 s. - webmaster@yulucn.com