当前位置: 首页>>代码示例>>C#>>正文


C# Regex.ToString方法代码示例

本文整理汇总了C#中Regex.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.ToString方法的具体用法?C# Regex.ToString怎么用?C# Regex.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Regex的用法示例。


在下文中一共展示了Regex.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnchoredRegex

 public void AnchoredRegex()
 {
     Regex re = new Regex(@"fox", RegexOptions.Anchored);
     string text = "The quick brown fox jumped over the lazy dog.";
     Assert.False(re.Match(text).IsSuccess, "{0} matched \"{1}\"", re.ToString(), text);
     Assert.True(re.Match(text, 16).IsSuccess,
         "{0} did not match \"{1}\" at {2:d}", re.ToString(), text, 16);
 }
开发者ID:MichaelBrazier,项目名称:brasswork-regex,代码行数:8,代码来源:MatchingTests.cs

示例2: AnchoredEmpty

 public void AnchoredEmpty()
 {
     Regex re = new Regex(@"\w*", RegexOptions.Anchored);
     string text = "The quick brown fox jumped over the lazy dog.";
     Match m = re.Match(text);
     Assert.True(m.IsSuccess, "{0} did not match \"{1}\" on pass 1", re.ToString(), text);
     m = m.FindNext();
     Assert.True(m.IsSuccess, "{0} did not match \"{1}\" on pass 2", re.ToString(), text);
     m = m.FindNext();
     Assert.False(m.IsSuccess, "{0} matched \"{1}\" on pass 3", re.ToString(), text);
     Assert.Throws<InvalidOperationException>(() => m.FindNext());
 }
开发者ID:MichaelBrazier,项目名称:brasswork-regex,代码行数:12,代码来源:MatchingTests.cs

示例3: Main

    static void Main()
    {
        try
        {
            string path = @"..\..\test.txt";
            string pathToReadTemplate = @"..\..\words.txt";
            string pathToWrite = @"..\..\result.txt";
            StreamReader reader = new StreamReader(path);
            using (reader)
            {
                string content = reader.ReadToEnd();
                string searchItem;
                int count = 0;

                StreamWriter writer = new StreamWriter(pathToWrite, false, Encoding.GetEncoding("UTF-8"));
                using (writer)
                {
                    string[] patternArray = File.ReadAllLines(pathToReadTemplate);

                    string[] result = new string[patternArray.Length - 1];

                    for (int i = 0; i < patternArray.Length - 1; i++)
                    {

                        searchItem = patternArray[i];
                        count = new Regex(searchItem).Matches(content).Count;
                        result[i] = count.ToString() + "-" + searchItem;
                    }
                    Array.Sort(result);
                    Array.Reverse(result);
                    for (int i = 0; i < result.Length; i++)
                    {
                        writer.WriteLine(result[i]);
                        writer.Flush();
                    }

                }
            }
        }
        catch (FileNotFoundException fe)
        {
            Console.WriteLine("{0}",fe.Message);
        }
        catch (DirectoryNotFoundException fe)
        {
            Console.WriteLine("{0}", fe.Message);
        }
        catch (IOException fe)
        {
            Console.WriteLine("{0}", fe.Message);
        }
    }
开发者ID:kicata,项目名称:CSharpPartTwoNew,代码行数:52,代码来源:13+CountingWordsBetweenTwoFiles.cs

示例4: fnValidateDateFormat

    public bool fnValidateDateFormat(string strDate)
    {
        Boolean Bflag = true;
        Regex regexDt = new Regex("(^(((([1-9])|([0][1-9])|([1-2][0-9])|(30))\\-([A,a][P,p][R,r]|[J,j][U,u][N,n]|[S,s][E,e][P,p]|[N,n][O,o][V,v]))|((([1-9])|([0][1-9])|([1-2][0-9])|([3][0-1]))\\-([J,j][A,a][N,n]|[M,m][A,a][R,r]|[M,m][A,a][Y,y]|[J,j][U,u][L,l]|[A,a][U,u][G,g]|[O,o][C,c][T,t]|[D,d][E,e][C,c])))\\-[0-9]{4}$)|(^(([1-9])|([0][1-9])|([1][0-9])|([2][0-8]))\\-([F,f][E,e][B,b])\\-[0-9]{2}(([02468][1235679])|([13579][01345789]))$)|(^(([1-9])|([0][1-9])|([1][0-9])|([2][0-9]))\\-([F,f][E,e][B,b])\\-[0-9]{2}(([02468][048])|([13579][26]))$)");

        Match mtStartDt = Regex.Match(strDate, regexDt.ToString());

        if (!mtStartDt.Success)
        {
            Bflag = false;

        }
        return Bflag;
    }
开发者ID:progressiveinfotech,项目名称:PRO-FY13-18_Habib-al-Mulla,代码行数:14,代码来源:CommonFunction.cs

示例5: Ctor

 public static void Ctor(string pattern, RegexOptions options, TimeSpan matchTimeout)
 {
     if (matchTimeout == Timeout.InfiniteTimeSpan)
     {
         if (options == RegexOptions.None)
         {
             Regex regex1 = new Regex(pattern);
             Assert.Equal(pattern, regex1.ToString());
             Assert.Equal(options, regex1.Options);
             Assert.False(regex1.RightToLeft);
             Assert.Equal(matchTimeout, regex1.MatchTimeout);
         }
         Regex regex2 = new Regex(pattern, options);
         Assert.Equal(pattern, regex2.ToString());
         Assert.Equal(options, regex2.Options);
         Assert.Equal((options & RegexOptions.RightToLeft) != 0, regex2.RightToLeft);
         Assert.Equal(matchTimeout, regex2.MatchTimeout);
     }
     Regex regex3 = new Regex(pattern, options, matchTimeout);
     Assert.Equal(pattern, regex3.ToString());
     Assert.Equal(options, regex3.Options);
     Assert.Equal((options & RegexOptions.RightToLeft) != 0, regex3.RightToLeft);
     Assert.Equal(matchTimeout, regex3.MatchTimeout);
 }
开发者ID:chcosta,项目名称:corefx,代码行数:24,代码来源:Regex.Ctor.Tests.cs

示例6: OutOfBounds

 public void OutOfBounds()
 {
     Regex re = new Regex(@"abc");
     string text = "abc";
     Assert.Throws<ArgumentOutOfRangeException>(() => re.Match(text, -1),
         "{0} matched at {1:d}", re.ToString(), -1);
     Assert.Throws<ArgumentOutOfRangeException>(() => re.Match(text, 4),
         "{0} matched at {1:d}", re.ToString(), 4);
 }
开发者ID:MichaelBrazier,项目名称:brasswork-regex,代码行数:9,代码来源:MatchingTests.cs

示例7: mainLoop

    public string mainLoop(int startTime)
    {
        Information information = new Information();
         ChannelActions ChanActs = new ChannelActions();
         ChanModes mode = new ChanModes();
         Loader load = new Loader();
         CTCP ctcp = new CTCP();
         UserControl users = new UserControl();
         httpRegex = new Regex(@"(?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)?)|(?:ftp://(?:(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*)(?::(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;?&=])*))[email protected])?(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?))(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[?:@&=])*))*)))");
         try
         {

         ThreadStart userThreadStart = new ThreadStart(users.userControl);
         Thread userThread = new Thread(userThreadStart);
         userThread.Start();
         }
         catch (Exception e)
         {
         Console.WriteLine(e.ToString());
         }

         while (true)
         {
         while ((inputLine = reader.ReadLine()) != null)
         {
             Console.WriteLine(inputLine);

             if (inputLine.IndexOf("376") >= 0) //End of MOTD
             {
                 writer.WriteLine("JOIN " + channel);
                 writer.Flush();

          }
             else
                 break;

             while ((inputLine = reader.ReadLine()) != null)
             {
                 Console.WriteLine(inputLine);

                 if (ctcp.isCTCP())
                     ctcp.processCTCPType();

                 else if (inputLine == ("PING :" + server))
                 {
                     writer.WriteLine("PONG " + server);
                     writer.Flush();
                 }

                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": op me") >= 0 && information.sender() == owner)
                 {
                     mode.setMode("+o", owner);
                 }

                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": op") >= 0)
                 {
                     string realSender = information.sender();
                     string realMsg = information.msg();
                     information.sendNamesToSrv();
                     inputLine = reader.ReadLine();
                     if (information.isOped(realSender) || information.sender() == owner && information.senderHost() == ownerhost)
                         mode.setMode("+o", realMsg.Substring(nick.Length + 5));

                 }

                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": voice me") >= 0 || inputLine.ToLower().IndexOf(nick.ToLower() + ": voice ") >= 0)
                 {
                     mode.setMode("+v", information.sender());
                 }

                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": uptime") >= 0)
                 {
                     Uptime uptime = new Uptime();
                     uptime.uptime(startTime);

                 }

                 else if (inputLine.IndexOf("PART " + channel) >= 0)
                 {
                     users.userPart();

                 }

                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": die") >= 0 && information.sender() == owner)
                 {
                     writer.WriteLine("QUIT :My master killed me");
                     writer.Flush();
                     cleanup();

                     return "ok";
                 }
                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": topic") >=0  && information.sender() == owner)
                 {
                     mode.setTopic();
                 }
                 else if (inputLine.ToLower().IndexOf(nick.ToLower() + ": !load") >= 0 && information.sender() == owner)
                 {

                     load.createAD("load");

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sharp-bot-svn,代码行数:101,代码来源:ircLib.cs

示例8: ReadSpawn

        /// <summary>
        /// Function um die Spawn Dateien zu lesen.
        /// </summary>
        public StructSpawn ReadSpawn()
        {
            string SpawnFileText = File.ReadAllText(SpawnFile).Replace('.', ',');
            StructSpawn returnSpawn = new StructSpawn();
            returnSpawn.MoverIDs = new System.Windows.Forms.ListView.ListViewItemCollection(lv_movers);

            SpawnFileText = SpawnFileText.Replace("\r", string.Empty);

            Regex zahl      = new Regex(@"[\d]+");
            Regex floatZahl = new Regex(@"[\d]+[,]?[\d]*");

            Regex[] spawnCMDs = new Regex[] {new Regex(@"MOB " + zahl.ToString()),
                                             new Regex(@"COUNT " + zahl.ToString()),
                                             new Regex(@"MOVING " + zahl.ToString()),
                                             new Regex(@"PENYA " + floatZahl.ToString()),
                                             new Regex(@"EXP " + floatZahl.ToString()),
                                             new Regex(@"DROP " + floatZahl.ToString()),
                                             new Regex(@"POS " + floatZahl.ToString() + " " + floatZahl.ToString() + " " + floatZahl.ToString()),
                                             new Regex(@"WORLD " + floatZahl.ToString()),
                                             new Regex(@"RANGE " + floatZahl.ToString()),
                                             new Regex(@"AGGRO " + floatZahl.ToString()),
                                             new Regex(@"RESPAWNTIME " + zahl.ToString()),
                                             new Regex(@"MOVINGINTERVAL " + floatZahl.ToString()),
                                             new Regex(@"SIZE " + zahl.ToString())};

            string[] lines = SpawnFileText.Split('\n');

            try
            {
                foreach(string line in lines)
                {
                    if(!line.StartsWith("//"))
                    {
                        for(int i = 0; i < spawnCMDs.Length; i++)
                        {
                            if(spawnCMDs[i].IsMatch(line))
                            {
                                if(i == 0) // Mob-ID
                                {
                                    ListViewItem lvItem = new ListViewItem(zahl.Matches(line)[0].ToString());
                                    lvItem.SubItems.Add(findeMob(int.Parse(zahl.Matches(line)[0].ToString())));

                                    returnSpawn.MoverIDs.Add(lvItem);
                                    break;
                                }
                                else if(i == 1) // Mob Count
                                {
                                    returnSpawn.Count = int.Parse(zahl.Matches(line)[0].ToString());
                                    break;
                                }
                                else if(i == 2) // Move
                                {
                                    returnSpawn.Move = line.Contains("1");
                                    break;
                                }
                                else if(i == 3) // Penya
                                {
                                    returnSpawn.Penya = float.Parse(floatZahl.Matches(line.Replace('.', ','))[0].ToString());
                                    break;
                                }
                                else if(i == 4) // EXP-Rate
                                {
                                    returnSpawn.Exp   = float.Parse(floatZahl.Matches(line.Replace('.', ','))[0].ToString());
                                    break;
                                }
                                else if(i == 5) // Drop
                                {
                                    returnSpawn.Drop  = float.Parse(floatZahl.Matches(line.Replace('.', ','))[0].ToString());
                                    break;
                                }
                                else if(i == 6) // Position
                                {
                                    returnSpawn.Pos.X  = float.Parse(floatZahl.Matches(line)[0].ToString());
                                    returnSpawn.Pos.Y  = float.Parse(floatZahl.Matches(line)[1].ToString());
                                    returnSpawn.Pos.Z  = float.Parse(floatZahl.Matches(line)[2].ToString());
                                    break;
                                }
                                else if(i == 7) // Position.World
                                {
                                    returnSpawn.Pos.World = int.Parse(zahl.Matches(line)[0].ToString());
                                    break;
                                }
                                else if(i == 8) // Angriff Range
                                {
                                    returnSpawn.Range  = float.Parse(floatZahl.Matches(line)[0].ToString());
                                    break;
                                }
                                else if(i == 9) // Aggro Chance
                                {
                                    returnSpawn.Aggro  = float.Parse(floatZahl.Matches(line)[0].ToString());
                                    break;
                                }
                                else if(i == 10) // Respwan Time
                                {
                                    returnSpawn.ReTime = int.Parse(zahl.Matches(line)[0].ToString());
                                    break;
                                }
//.........这里部分代码省略.........
开发者ID:coolzazzou,项目名称:Black-Orion,代码行数:101,代码来源:SpawnEditor.cs


注:本文中的Regex.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。