參考答案:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSD01
{
class Program
{
static void Main(string[] args)
{
// TODO
string input1, input2;
Console.Write("請輸入第一個字串>");
input1=Console.ReadLine();
Console.Write("請輸入第二個字串>");
input2=Console.ReadLine();
if (input1.Length > input2.Length)
Compare(input1, input2);
else
Compare(input2,input1);
Console.ReadLine();
}
// TODO
public static void Compare(string lw,string sw)
{
bool include = false;
for (int i = 0; i < lw.Length - sw.Length; i++)
{
if (sw == lw.Substring(i, sw.Length))
{
include = true ;
break;
}
else
include = false;
}
if(include)
Console.WriteLine("字串" + lw + "包含字串" + sw);
else
Console.WriteLine("字串" + lw + "不包含字串" + sw);
}
}
}
執行結果:
留言列表