Comment detail

文字変換表に基く文字列の変換 (Nested Flatten)

発展版です。 最近C#3.0にしたので嬉しくて拡張メソッドにしてみました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
//http://ja.doukaku.org/148/ 投稿用
using System;
static class Program {
    static string Tr(this string target, string from, string to) {
        for(int i = 0; i <= from[2] - from[0]; i++) {
            target = target.Replace((char)(from[0] + i), (char)(to[0] + i));
        }
        return target;
    }
    static void Main(string[] args) {
        Console.WriteLine("ABCDEF".Tr("A-D", "a-d"));
        Console.ReadLine();
    }
}

ごめんなさい。間違えました。(2)拡張版でした。

Index

Feed

Other

Link

Pathtraq

loading...