Reputation: 65
I'm trying to write some code that checks whether blurred pictures that the user has picked is the same as their normal counterparts.
It uses the image location string to compare each selection once all 6 picture choices have been picked. So far, it has the normal pictures as an array of picture locations in a text file, as a sort of password.
Essentially, I want to take the last part of the image location string (the filename part) of each entry in the password string array and compare it with the current selection (array) of blurred pictures the user has clicked
So far the comparing part goes like this:
//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();
}
However, this doesn't work because the image location for passwordEntered[] looks into a different directory from passwordLocation[] (i.e. if "...filepath/cat.jpg" == "...filepath/Blurred/cat.jpg").
I'm thinking Substrings are the solution here, but I'm not sure how to use them properly.
Can anyone help or give me an example of how to extract substrings?
Upvotes: 0
Views: 1424
Reputation: 499382
The Path
class has this built in - the GetFileName
method.
if ( Path.GetFileName(pathOne) == Path.GetFileName(pathTwo) )
Upvotes: 1
Reputation: 35407
Use System.IO.Path.GetFileName(path)
method:
string fileone = GetFileName(pathone); // > fileone.ext
string filetwo = GetFileName(pathtwo); // > filetwo.ext
if(fileone == filetwo) doStuff();
Upvotes: 3