 |
|
อาจารย์ให้อธิบายว่าโปรแกรมโค้ดมันทํางานอย่างไร ผมไม่รู้จะอธิบายการทํางานอย่างไร ไม่ค่อยรู้โปรแกรม C#
รบกวนอีกครั้งนะครับ คุณ By : 01000010 ขอบพระคุณมากครับ
Code (C#)
โปรแกรม 1
static void Main()
{
string[] words = new string[] { "bad", "boy", "baad", "bear", "bend" };
foreach (string word in words)
if (Regex.IsMatch(word, "ba+"))
Console.WriteLine(word);
Console.Read();
}
}
}
Code (C#)
โปรแกรม 2
static void Main()
{
string[] words = new string[] { "bad", "boy", "baad", "bear", "bend" };
foreach (string word in words)
if (Regex.IsMatch(word, "ba{2}d"))
Console.WriteLine(word);
}
}
}
Code (C#)
โปรแกรม 3
static void Main()
{
string[] words = new string[] { "Part", "of", "this", "<b>string</b>", "is", "bold" };
string regExp = "<.*>";
MatchCollection aMatch;
foreach (string word in words)
{
if (Regex.IsMatch(word, regExp))
{
aMatch = Regex.Matches(word, regExp);
for (int i = 0; i < aMatch.Count; i++)
Console.WriteLine(aMatch[i].Value);
}
}
}
Code (C#)
โปรแกรม 4
static void Main() {
string st1 = "the quick browm fox jumped over the lazy dog";
MatchCollection matchSet;
matchSet = Regex.Matches(st1, ".");
foreach (Match aMatch in matchSet)
Console.WriteLine("matches at: " + aMatch.Index);
}
}
Code (C#)
โปรแกรม 5
static void Main() {
string st1 = "the quick brown fox jumped over the lazy dog one time";
MatchCollection matchSet;
matchSet = Regex.Matches(st1, "t.e");
foreach (Match aMatch in matchSet)
Console.WriteLine("Matches at: " + aMatch.Index);
}
}
Code (C#)
โปรแกรม 6
static void Main()
{
string[] words = new string[] { "Part", "of", "this", "<b>string</b>", "is", "bold" };
string regExp = "<.*>";
MatchCollection aMatch;
foreach (string word in words)
{
if (Regex.IsMatch(word, regExp))
{
aMatch = Regex.Matches(word, regExp);
for (int i = 0; i < aMatch.Count; i++)
Console.WriteLine(aMatch[i].Value);
}
}
}
Code (C#)
โปรแกรม 7
static void Main()
{
string words = "08/14/57 46 02/25/59 45 06/05/85 18" +
"03/12/88 16 09/09/90 13";
string regExp1 = "(\\s\\d{2}\\s)";
MatchCollection matchSet = Regex.Matches(words,regExp1);
foreach (Match aMatch in matchSet)
Console.WriteLine(aMatch.Groups[0].Captures[0]);
}
}
Code (C#)
โปรแกรม 8
static void Main() {
string words = "02/14/57 46 02/25/59 45 06/05/85 18 " +
"03/12/88 16 09/09/90 13" ;
string regExp1 = "(?<dates>(\\d{2}/\\d{2}/\\d{2}))\\s";
MatchCollection matchSet = Regex.Matches(words,regExp1);
foreach (Match aMatch in matchSet)
Console.WriteLine("Data: {0}", aMatch.Groups["dates"]);
}
}
}
Code (C#)
โปรแกรม 9
static void Main()
{
string dates = "08/14/57 46 02/25/59 45 06/05/85 18 " +
"03/12/88 16 09/09/90 13";
string regExp = "(?<dates>(\\d{2}/\\d{2}\\d{2}))\\s(?<ages>(\\d{2}))\\s";
MatchCollection matchSet;
matchSet = Regex.Matches(dates, regExp);
Console.WriteLine();
foreach (Match aMatch in matchSet)
{
foreach (Capture aCapture in aMatch.Groups
["dates"].Captures)
Console.WriteLine("dates capture: " + aCapture.ToString());
foreach (Capture aCapture in aMatch.Groups["ages"].Captures)
Console.WriteLine("age capture:" + aCapture.ToString());
}
}
}
Tag : .NET, C#
|
|
 |
 |
 |
 |
Date :
2013-08-28 02:40:19 |
By :
กวาง |
View :
909 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |