開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の15章(文字列)、15.6(練習問題)、練習15-2.を取り組んでみる。
コード
using System; using System.Text.RegularExpressions; namespace sample15_1 { class Program { static void Main(string[] args) { string sentence = "We hold these truths to be self-evident, " + "that all men are created equal, " + "that they are endowed by their Creator with certain unalienable Rights, " + "that among these are Life, Liberty and the pursuit of Happiness."; Regex reg = new Regex(@"\b\w+\b"); foreach (var item in reg.Matches(sentence)) { Console.WriteLine(item); } } } }
入出力結果(Terminal)
We hold these truths to be self evident that all men are created equal that they are endowed by their Creator with certain unalienable Rights that among these are Life Liberty and the pursuit of Happiness Press any key to continue...
0 コメント:
コメントを投稿