此刻我正在上传2个txt文件。在文件'A'中我有一个字母列表,在'B'文件中我有两个单词,我正在阅读这两个文件,我将它们添加到列表中。目标是根据'A'文件的字母来查找是否可以从'B'文件形成单词。例:
'A'文件的内容:E B Y O P D R B A.
'B'文件的内容:POBEDA,COBALT
在这种情况下,在POBEDA中找到的单词
我正在使用Web服务来执行该过程
这是Web服务:
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string Leerdata()
{
var path = Directory.EnumerateFiles(@"C:\Users\thoma\source\repos\NewShoreApp\NewShoreApp\Data\", "*.txt");
List<string> list = path.ToList();
Parallel.ForEach(path, current =>
{
string[] lines = File.ReadAllLines(current);
list.AddRange(lines.ToList());
});
return String.Join(",", list);
}
}
这是控制器:
namespace NewShoreApp.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase[] files)
{
if (ModelState.IsValid)
{
try
{
foreach (HttpPostedFileBase file in files)
{
if (file != null)
{
var ServerPath = Path.Combine(Server.MapPath("~/Data"), Path.GetFileName(file.FileName));
file.SaveAs(ServerPath);
}
}
ViewBag.FileStatus = "File uploaded successfully.";
}
catch (Exception)
{
ViewBag.FileStatus = "Error while file uploading.";
}
}
return View("Index");
}
}
}
这是模型:
namespace NewShoreApp.Models
{
public class Data
{
//
[DataType(DataType.Upload)]
[Display(Name = "Upload File")]
[Required(ErrorMessage = "Please choose file to upload.")]
public HttpPostedFileBase[] files { get; set; }
}
}
只是一个简单的算法解决您的问题。
(你可以改进这个算法,这个算法仅供你参考)
文件“A”和“B”之间的匹配过程应如下所示: