I’m trying to get the first occurrence in my substring start point:
string dir = Request.MapPath(Request.ApplicationPath) + "\\App_GlobalResources\\";
foreach (var file in Directory.EnumerateFiles(dir, "*.resx"))
{
ddlResources.Items.Add(new ListItem { Text = file.Substring(firstoccuranceof("."), file.LastIndexOf(".")), Value = file });
}
if I do file.Substring(file.IndexOf(“.”), file.LastIndexOf(“.”)) I get an error
To answer your actual question – you can use
string.IndexOfto get the first occurrence of a character. Note that you’ll need to subtract this value from yourLastIndexOfcall, sinceSubstring‘s second parameter is the number of characters to fetch, not a start and end index.However… Instead of parsing the names, you can just use Path.GetFilenameWithoutExtension to get the filename directly.