yohei #4432(2007/11/27 10:13 GMT) [ C# ] Rating0/0=0.00
C#3.0で拡張メソッドを使ってみました.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
using System; using System.Linq; using System.Collections.Generic; static class Program { static string RemoveAfter(this string s, char ch) { int index = s.IndexOf(ch); return (0 <= index && index < s.Length - 1) ? s.Remove(index + 1) : s; } static void ls(IEnumerable<string> pathList, string path) { if (!path.EndsWith("/")) path += '/'; var x = from y in pathList where y.StartsWith(path) select '"' + y.Substring(path.Length).RemoveAfter('/') + '"'; Console.WriteLine("[{0}]", string.Join(", ", x.Distinct().ToArray())); } static void Main(string[] args) { string[] pathList = { "aaa/bbb", "aaa/ccc", "aaa/ddd/eee", "bbb/ddd/eee" }; ls(pathList, "aaa/"); ls(pathList, "aaa/ddd/"); } }
Rating0/0=0.00-0+
[ reply ]
yohei
#4432()
[
C#
]
Rating0/0=0.00
C#3.0で拡張メソッドを使ってみました.
Rating0/0=0.00-0+
[ reply ]