C#的第一个例子(将html的大写标签转换为小写)
看了好久的书,总算是可以实现些自己需要的功能.
一直以来.想把自己用的wiz中的html大小标签转换成小写,这样子才更合乎w3c.
今天终于实现了一小点...
过程如下:
1.先写了个cmd的程序

1 using System;
2 using System.Text.RegularExpressions;
3 namespace LowCaseOrUpCaseTransform
4 {
5 class Program
6 {
7
8 static string CapText(Match m)
9 {
10 // Get the matched string.
11 string x = m.ToString();
12 return x.ToLower();
13 }
14
15 static void Main()
16 {
17 string text = "<INPUT id=\"SearchInput\">";
18
19 System.Console.WriteLine("text=[" + text + "]");
20
21 Regex rx = new Regex(@"</?[^>]+>");
22
23 string result = rx.Replace(text, new MatchEvaluator(Program.CapText));
24
25 System.Console.WriteLine("result=[" + result + "]");
26 Console.WriteLine();
27 Console.ReadKey();
28 }
29 }
30 }
2.将cmd程序更改为windows的程序.

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Text.RegularExpressions;
10
11 namespace UpperToLowerHtml
12 {
13 public partial class Form1 : Form
14 {
15 public Form1()
16 {
17 InitializeComponent();
18 }
19
20
21 static string CapText(Match m)
22 {
23 // Get the matched string.
24 string x = m.ToString();
25 return x.ToLower();
26 }
27
28
29 private void buttonSwitch_Click(object sender, EventArgs e)
30 {
31 Regex rx = new Regex(@"</?[^>]+>");
32 this.textBoxOutPut.Text = rx.Replace(this.textBoxInPut.Text, new MatchEvaluator(Form1.CapText));
33 }
34 }
35 }
3.目标.希望可以做完善.目前还不会操作文件.只能这样子验证代码的正确性了.