我試着讓我的子串起始點第一次出現可以有人幫助我如何獲得一個字符中第一次出現的子串
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 });
}
,如果我做file.Substring(file.IndexOf(」。 「),file.LastIndexOf(」「)),我得到一個錯誤
你能舉一個具體的例子,對於一個給定的字符串,你想得到什麼?例如:如果字符串是'「Hello_world.jpg」'應該是什麼結果? – 2011-12-28 02:37:55
您有一個語法錯誤,即在新的ListItem {...}中使用'{''}'。另外,爲什麼要指定Text =和Value = ...他們什麼都不做,最後你可能是想得到沒有.resx擴展名的文件名,並且使用:file.Substring(0,fileLastIndexOf (「。」)) – 2011-12-28 02:50:32