【问题标题】:is it a good practice to use string manipulation in c#在 c# 中使用字符串操作是一个好习惯吗
【发布时间】:2024-04-15 14:50:02
【问题描述】:

我需要提取部分字符串,我发现了 2 种方法,哪一种在编码实践中更好,使用字符串操作是一种好的编码实践吗?有没有其他方法可以完成这项任务?

string test = "name.jpg_add1_srcimages_pagetest.htm";
string img_name = test.substring(0,str.LastIndexOf("_add"));
//or 
string[] img_prop = test.Split('_');
string img_n = img_prop[0]

【问题讨论】:

  • 使用字符串的分割功能就好了。

标签: string c#-4.0 split substring coding-style


【解决方案1】:

对于性能string.Split进行了优化。

【讨论】:

    最近更新 更多