当前位置: 代码迷 >> ASP.NET >> 这个字符串如何截取
  详细解决方案

这个字符串如何截取

热度:6122   发布时间:2013-02-25 00:00:00.0
这个字符串怎么截取?
有这么一种规格的字符串,如:

string s1="/1/1/";
string s2="/1/2/";
string s3="/1/13/";

问,如果将最后一段/与/间的内容(位数不确定)去掉,只保留前半截?结果像这样:"/1/"


------解决方案--------------------------------------------------------
trimend("/")
trimend("/")
------解决方案--------------------------------------------------------
只要实现了就好,哪有什么好看不好看的
------解决方案--------------------------------------------------------
SQL code
--你也可以在数据库中处理declare @T table (col varchar(8))insert into @Tselect '/1/1/43/' union allselect '/1/2/' union allselect '/1/13/1/'select LEFT(col,LEN(col)-CHARINDEX('/',RIGHT(REVERSE(col),LEN(col)-1))) from @T/*/1/1//1//1/13/*/
------解决方案--------------------------------------------------------
探讨

string s1 = "/1/1/";
Regex reg = new Regex(@"^/\d+/");
Console.WriteLine(reg.Match(s1).Value);
  相关解决方案