C#中Regex應用一例
來源:互聯網
上載者:User
//蛙蛙推薦:C#中Regex應用一例
//我上次的那個問題用C#來解決了,貼一下先
//首先把本文所有代碼複製儲存為arr_reg.cs
//然後把下面的代碼用CSC編譯成控制台程式後就可以看到結果了,編譯命令如下:
//csc /t:exe arr_reg.cs
using System;
using System.Text.RegularExpressions;
public class RegexTest{
public static void wawa_reg(){
string[] arr=new string[15]; //定義一個字串數組
arr[0]="1,網站會員管理"; //填充數組
arr[1]="2,管理員權限管理";
arr[2]="3,供求資訊管理";
arr[3]="4,產品展示管理";
arr[4]="5,企業之窗管理";
arr[5]="6,信用企業管理";
arr[6]="7,專家庫管理";
arr[7]="8,電子刊管理";
arr[8]="9,軟體下載管理";
arr[9]="10,行業分類管理";
arr[10]="11,網站系統管理";
arr[11]="12,特色產業管理";
arr[12]="13,人才招聘管理";
arr[13]="14,廣告管理";
arr[14]="15,專案管理";
for(int i=0;i<15;i++){ //遍曆數組,輸出每個元素的左邊和右邊部分
string s1 = Regex.Replace(arr[i], @"^(d*),(.*)d*$", "$1");
string s2 = Regex.Replace(arr[i], @"^(d*),(.*)d*$", "$2");
Console.WriteLine("arr["+i+"].s1= "+s1+"arr["+i+"].s2= "+s2);
}
}
public static void Main()
{
wawa_reg();
}
}
//可惜我用VBS還是解決不了呀,唉,慢慢研究吧,這個禮拜基本上都鼓搗Regex了,本來還想學點兒SQLSERVER裡的視圖,索引和預存程序呢,不知道時間還夠不夠