Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 比较不同文件夹中的文件名字符串_C#_String_String Comparison - Fatal编程技术网

C# 比较不同文件夹中的文件名字符串

C# 比较不同文件夹中的文件名字符串,c#,string,string-comparison,C#,String,String Comparison,我正在尝试编写一些代码,检查用户拾取的模糊图片是否与正常图片相同 一旦所有6个图片选择都被选中,它将使用图像位置字符串来比较每个选择。 到目前为止,它将普通图片作为文本文件中的图片位置数组,作为一种密码 本质上,我希望获取密码字符串数组中每个条目的图像位置字符串(文件名部分)的最后一部分,并将其与用户单击的模糊图片的当前选择(数组)进行比较 到目前为止,比较部分如下所示: //Test to see whether the password entered is the same as the

我正在尝试编写一些代码,检查用户拾取的模糊图片是否与正常图片相同

一旦所有6个图片选择都被选中,它将使用图像位置字符串来比较每个选择。 到目前为止,它将普通图片作为文本文件中的图片位置数组,作为一种密码

本质上,我希望获取密码字符串数组中每个条目的图像位置字符串(文件名部分)的最后一部分,并将其与用户单击的模糊图片的当前选择(数组)进行比较

到目前为止,比较部分如下所示:

//Test to see whether the password entered is the same as the saved password.
if (passwordEntered[0] == passwordLocation[0] && passwordEntered[1] == passwordLocation[1] && passwordEntered[2] == passwordLocation[2])
{
      MessageBox.Show(TextResources.alertMessageText.passwordCorrect);
      Application.Exit();
}
但是,这不起作用,因为passwordEntered[]的图像位置与passwordLocation[]位于不同的目录中(即,如果“…filepath/cat.jpg”==“…filepath/fuzzle/cat.jpg”)

我认为子字符串是这里的解决方案,但我不确定如何正确使用它们

有人可以帮助我或给我一个如何提取子字符串的示例吗?

使用方法:

使用方法:

这个类有一个内置的方法

这个类有一个内置的方法


知道有点晚了,但谢谢,这正是我需要的,得到名字正是我想做的,但我不知道怎么做。知道有点晚了,但谢谢,这正是我需要的,得到名字正是我想做的,但我不知道怎么做。
string fileone = GetFileName(pathone); // > fileone.ext
string filetwo = GetFileName(pathtwo); // > filetwo.ext

if(fileone == filetwo) doStuff();
if ( Path.GetFileName(pathOne) == Path.GetFileName(pathTwo) )