【发布时间】: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