2012年3月8日木曜日

開発環境

  • Microsoft Windows 7 Home Premium (OS)
  • Microsoft Visual C# 2010 Express Edition (IDE)
  • 言語: C#

『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の第15章(文字列)の14.6(練習問題)、練習15-2.を解いてみる。

練習15-2.

コード

using System;
using System.Text;
using System.Text.RegularExpressions;

class Tester
{
    public void Run()
    {
        string str = "We hold these truths to be self-evident," +
            "that all men are created equals," +
            "that they are endowed by their Creator with certain unalienable Rights," +
            "that among these are Life," +
            "Liberty and the pursuit of Happiness.";
        StringBuilder output = new StringBuilder();
        int count = 0;
        Regex reg = new Regex(" |,");
        foreach (string item in reg.Split(str))
        {
            output.AppendFormat("{0}: {1}\n", count, item);
            count++;
        }
        Console.WriteLine("{0}", output);

    }
    static void Main()
    {
        Tester t = new Tester();
        t.Run();
    }
}

入出力結果(Console Window)

0: We
1: hold
2: these
3: truths
4: to
5: be
6: self-evident
7: that
8: all
9: men
10: are
11: created
12: equals
13: that
14: they
15: are
16: endowed
17: by
18: their
19: Creator
20: with
21: certain
22: unalienable
23: Rights
24: that
25: among
26: these
27: are
28: Life
29: Liberty
30: and
31: the
32: pursuit
33: of
34: Happiness.

続行するには何かキーを押してください . . .

本書の問題はすらすら解けるようになってきたしJavaScript、jQueryの学習も進めているので、C#とJavaScriptを組み合わせた、ASP.NET Ajaxの学習も開始することに。レンタルしている共用サーバーも放置状態なので。

合わせて読んでいる書籍。

  1. 独習 ASP.NET 第3版 山田 祥寛 (著)
  2. 正規表現の理解を深めるために本書に加えて著Jeffrey E. F. Friedl著, 株式会社ロングテール/長尾 高弘訳 『詳説 正規表現 第3版』(オライリー・ジャパン発行)もあわせて読む。
  3. C#の理解を深めるために本書に加えてProgramming C# 3.0, Fifth Edition, by Jesse Liberty and Donald Xie. Copyright 2008 O'Reilly Meia, Inc., 978-9-596-52743-3 (邦題『プログラミングC# 第5版』オライリー・ジャパン刊、978-4-87311-396-8)を読む。
  4. さらにC#を楽しみながら理解するためにHead First C# ―頭とからだで覚えるC#の基本 Andrew Stellman (著), Jennifer Greene (著), 佐藤 嘉一 (監修), 木下 哲也 (翻訳)

0 コメント:

コメントを投稿