【发布时间】:2015-05-07 16:32:37
【问题描述】:
我浏览了string 类的文档并没有看到任何将任意数量的字符串组合成单个字符串的好工具。我可以在我的程序中提出的最佳程序是
string [] assetUrlPieces = { Server.MapPath("~/assets/"),
"organizationName/",
"categoryName/",
(Guid.NewGuid().ToString() + "/"),
(Path.GetFileNameWithoutExtension(file.FileName) + "/")
};
string assetUrl = combinedString(assetUrlPieces);
private string combinedString ( string [] pieces )
{
string alltogether = "";
foreach (string thispiece in pieces) alltogether += alltogether + thispiece;
return alltogether;
}
但这看起来代码太多,效率太低(来自字符串添加)和尴尬。
【问题讨论】:
标签: c# string algorithm data-structures