如何将此sql语句转换为linq。
declare @S nvarchar(100) = 'www.abc.com/a/b/c/d/e/f/g/h/i'
while PATINDEX('%[/]%' , @S) > 0 BEGIN
SET @S = LEFT (@S,LEN(@S) - PATINDEX('%[/]%' , REVERSE(@S)))
SELECT @S
END
答案 0 :(得分:2)
这应该这样做:
StringBuilder sb = new StringBuilder();
string url = "www.abc.com/a/b/c/d/e/f/g/h/i";
var q = url.Split('/').Select(s => sb.Append((sb.Length > 0 ? "/" : "") + s).ToString());
foreach(string output in q.Reverse())
Console.WriteLine(output);
<强>输出:强>
www.abc.com/a/b/c/d/e/f/g/h/i
www.abc.com/a/b/c/d/e/f/g/h
www.abc.com/a/b/c/d/e/f/g
www.abc.com/a/b/c/d/e/f
www.abc.com/a/b/c/d/e
www.abc.com/a/b/c/d
www.abc.com/a/b/c
www.abc.com/a/b
www.abc.com/a
www.abc.com