如何使用此模式将此 sql 语句转换为 linq
How to convert this sql statement to linq with this pattern
如何将此 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
应该这样做:
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
如何将此 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
应该这样做:
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