C# 70-536 – Chapter 3 Searching, Modifying, and

  • 3249
  • 0
  • C#
  • 2011-05-11

C# 70-536 – Chapter 3 Searching, Modifying, and
Encoding Text

正規表示式:.NET和UNIX用的時候有點不太一樣,VS環境本身提供的「使用規則運算式」搜尋功能是採用UNIX的……

string pattern = @"(?ims)"".\s*(?<host>http:.*?)\s*"".*?(?<name>\b\w+).*?""\s*(?<ext>\..*?)\s*""";
string sample = @"select ID,"" http://localhost/TestSite/"" + MESTNR + "".doc"" from TestMestLayer ";

Regex reg = new Regex(pattern);
Match m = reg.Match(sample);

string url = "";
string sql = "";
//比對成功
if (m.Success)
{
	//取群組值
	url = String.Concat(m.Groups["host"].Value, m.Groups["name"].Value, m.Groups["ext"].Value);
}

//取代符合比對字串
sql = Regex.Replace(sample, pattern, "${name}");

Console.WriteLine(url);
Console.WriteLine(sql);

 

字元的編碼 & 解碼 (Encoding)

1.ASCII 只提供英文及數字。

2.System.Text.Encoding提供了編碼及解碼的處理。

3.Encoding.GetENcodings可取得支援的字碼頁清單。

image

讀檔 & 寫檔使用Encoding的範例請參考C# 70-536 – Chapter 2

 

相關連結:

[c#]Regular Expression抓取/取代特定資料的說明

MSDN: Regular Expression Language Elements

Regular Expression 工具:Rad Software Regular Expression Designer

Regular Sample : Regular Expression Library

 

Dotblogs 的標籤: