I have a list of strings
var lsNameList = new List<string>();
that is a list of file names. I want to iterate over a collection of files checking the file names for matches. If there is a match then append on a number. the number will be increments in one. eg If filename is in the list then append on 1 so it will be filename1. If filename1 is in the list then change it to filename2 and so on.
foreach (var SourceFile in SourceFiles)
if (lsNameList.Contains(SourceFile.Label.ToLower()))
// Add the name to the list but with a number at the end
I have the iteration and filename checking done but I have a problem when the number runs into double digits
var sLastCharacter = SourceFile.Label[SourceFile.Label.Length - 1].ToString();
var iLast = StringToInt(sLastCharacter);
What if SourceFile.Label is filename10. The last digit will be 0 and we will start all over again causing a infinite loop.
Is there a way around this?