c#中如何截取字符中某一符号前的值?例如string str ="23-明城",取-前面的数字。

如题所述

第1个回答  推荐于2018-03-14
char[] cutStr=str.split("-");
cutStr[0]即为你需要的值本回答被网友采纳
第2个回答  2013-05-15
能想到两种办法
1.用 Split 切分

2.int index = str.IndexOf("-")
string result = str.Substring(0,index + 1);本回答被提问者采纳
相似回答