您现在的位置: 365建站网 > 365文章 > 实现正则标签

实现正则标签

文章来源:365jz.com     点击数:124    更新时间:2009-09-12 17:00   参与评论

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;       //

/// <summary>
/// Cls_Regex 的摘要说明
/// </summary>
namespace Cls_Regex
{
    public class Cls_Regex
    {
        //前三个为使用前必须初始化的参数
        public string InStr = "";       //输入的源字符串
        public string LName = "";       //标签名称
        public int LCount = 0;          //标签参数个数
        public int len = 0;             //标签个数

        public Cls_Regex()
        {

        }

        //获得源字符串中标签的个数
        public int FucGetLen()
        {
            string label = @"\[" + LName.ToString() + "(\\|(\\d|\\w)+){" + LCount.ToString() + "}\\|" + LName.ToString() + "]";
            MatchCollection mc = Regex.Matches(InStr, label);
            len = mc.Count;
            return len;
        }

        //获得标签与参数
        //返回值为二维数组
        public string[,] FucGetLabel()
        {
            string label = @"\[" + LName.ToString() + "(\\|(\\d|\\w)+){" + LCount.ToString() + "}\\|" + LName.ToString() + "]";
            string str1 = "";
            FucGetLen();
            string[,] str3 = new string[len, LCount + 1];
            int i = 0, j = 0;
            MatchCollection mc1 = Regex.Matches(InStr, label);
            foreach (Match m1 in mc1)
            {
                str3[i, 0] = m1.Value.ToString();
                str1 = @"(\|(\d|\w)+){" + LCount.ToString() + "}\\|";
                MatchCollection mc2 = Regex.Matches(m1.Value.ToString(), str1);
                foreach (Match m2 in mc2)
                {
                    m2.Value.ToString();
                    string[] str2 = Regex.Split(m2.Value.ToString(), @"\|");
                    for (j = 1; j <= LCount; j++)
                    {
                        str3[i, j] = str2[j].ToString();
                    }
                }
                i++;
            }
            return str3;
        }
    }
}

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (124人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号