???? ID: 308252 - ????? ???????: 29 ??????? 2010 - ??????: 4.0

?????? ????????????? ?? ????? C# ?? ????? ?? ???? ???????? ?? ??? ???? ?? ??? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
???? Visual Basic .NET ??????? ?? ??? ?? ???? ??, ?????301264  (http://support.microsoft.com/kb/301264/ ) .

?? ???? ????? Microsoft .NET ????????? ????? ????????? ???????? ?? ???????? ???? ??::
  • System.Text.RegularExpressions

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ??? ?? ??? ???? ???? ????? ?? ????????? ???? ?? ???? ?????????? ??? ???????? ????? ???? ?? ??? ?????? ????????????? ?? ????? ???? ?? ??? ???? ?????? ??? ?????? ????????????? ???? ???????? ?? ?????????? ?? ?? ??????? ???????? ?? ??? ???? ?? ??? ?????? ???? ??? ?????? ???????? ?? ????? ????RegularExpressions??? ????? ???, ?? ?? ???? ??? ????? ???? ??? ?? ????????, ????? ????? ?? ??? ?? ???????? ???????? ???????? ??, ?? ???? ?? ???????? ???????? ?? ????? ?? ???? ???? ?? ??????? ??? ????????? ?? ?????? ???, ?? ?? ?-??? ??? ???????? ???? ?? ??? ?? ???????? ????? ???????

??????????

????? ???? outlines ???????? ?????????, ??????????, ??????? ??????, ?? ???? ???? ???:
  • Microsoft Visual C#
?? ???? ????? ?? ?? ?? ????? ???? ?? ?????? ???:
  • ????? C#
  • ?????? ?????????? ????????

?????? ????????????? ?? ????? ?? ???? ???????? ????? ?? ???

  1. ??????? ????? C#.
  2. ??? ??? ????? C# ????? ????????? ??????
  3. Specify theusingkeyword on theText.RegularExpressionsnamespace so that you will not be required to qualify declarations in those namespaces later in your code. Theusingstatement must be used prior to any other declarations:
    using System.Text.RegularExpressions;
    					
  4. Define a new regular expression that will use a pattern match to validate an e-mail address. The following regular expression is structured to accomplish three things:
    1. Capture the substring before the @ symbol and put that into the "user" group.
    2. Capture the substring after the @ symbol and put that into the "host" group.
    3. Make sure that the first half of the string does not have an @ symbol.
    Regex emailregex = new Regex("(?<user>[^@]+)@(?<host>.+)");
    					
  5. Define a new string containing a valid e-mail address. This provides a default value if the method's command-line argument is empty:
    String s = "johndoe@tempuri.org";
    					
  6. Check to see if there are any command-line parameters; if there are, retrieve the first parameter and assign it to the variable "s".
    if ( args.Length > 0 ) {
    	s = args[0];
    }
    					
  7. ?????Matchmethod to pass in the e-mail address variable and return a newMatch???????? ??? TheMatchobject will return regardless of whether any matches were found in the source string.
    Match m = emailregex.Match(s);
    					
  8. By examining the????????, ?? ????????? ?? ???? ???? ?? ??? ?? ???? ?? ?? ??????????????? ?? ?????? ????? ?? ??????? ???? ?? ???? ??? ?? ???, "??????????" ???????? ?? ?? ???? ?? ??? "?????"?????? ????????????????? ???
    if ( m.Success ) {
    	Console.WriteLine("User: " + m.Groups["user"].Value);
    	Console.WriteLine("Host: " + m.Groups["host"].Value);
     } else {
    	Console.WriteLine(s + " is not a valid email address");
    }
    Console.WriteLine();
    					
  9. ???? ?? ??? ?????? ????? ???? ????????? ?? ????? ?? ???, ??? ?? ????? ????????? ??????:
    System.Console.WriteLine("Press Enter to Continue...");
    System.Console.ReadLine();
    					
  10. ???? ????????? ??????
  11. ????????? ??? ??? ??????? ?-??? ??? ?? ????? ???? ??? ????? ?? ??????? ??? ????????? ?? ????? ?? ??? F5 ????? ?? ?? ??? ????????????????? ???????? ??.. ???? ?????? ???? ?? ??? ????????? ?? ??????? ???? ?? ??? ???? ??? ?????? ???:
    • ????? ????????????????? ??,????? ????-????? ????, ?? ???? ??????? ????. ??????????? ?? ??????? ???????? ??? ??? ?????? ???, ?? ??????? ???? ????? ??? ?? ?-??? ??? ????????? ????? F5 ?????, ?? ????? ???????????????? ???????? ???????? ????????? ?? ????? ?? ??? ???

      ??? ????? C# .NET 2003:????? ????????????????? ??,???. ???? ??? ??? ????? ??????????????? ??????????, ?? ???? ??????? ????. ?? ????????????? ?? ??????? ????????? ????,???? ?????? ?????? ?? ??????? ???? ????? ??? ?? ?-??? adress ????????? ????? F5 ????? ?? ?? ??? ????????????????? ???????? ????????? ?? ????? ?? ??? ???
    • ??? ???? ????? ?? ??????? ?? ???? ????????? ?? ????? ??????? ?? ??????? "bin\debug" ??????? ??? ??????? ????? ???? ??? ?-??? ??? ?? ?? ??????? ???? ????? ??? ?? ???? ??? ???????? ?? ??? ??????
    • ?? ????????? ?? ??? ???????? ????? ????? ?? ?????? ?????, ?? ??? ???? ??... ??????? ???? ?? ??? ?????????? ?? ????? ?????? ???? ????, ?? ????? ???? ?? ????? ???? ?? ??? ?-??? ??? ??????OK.

??????

???? ??????? ?? ???, ????? Microsoft ?????? ??????? (MSDN) ??? ?????? ?? ????::
?????? ?????????? ????????
HTTP://MSDN.Microsoft.com/Library/default.asp?URL=/Library/en-us/script56/HTML/ab0766e1-7037-45ed-aa23-706f58358c0e.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/ab0766e1-7037-45ed-aa23-706f58358c0e.asp?frame=true)

?????? ????????????? (JScript .NET) ?? ??? ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/28hw3sce .aspx (http://msdn2.microsoft.com/en-us/library/28hw3sce(vs.71).aspx)

?????? ????????????? (Visual Basic ??????? ????????????) ?? ??? ?????
HTTP://msdn2.Microsoft.com/en-us/library/6wzad2b2.aspx (http://msdn2.microsoft.com/en-us/library/6wzad2b2.aspx)

?????? ????????????? ???? ???? (Microsoft .NET Framework ??????? ??????)
(VS.71) http://MSDN.Microsoft.com/en-us/library/az24scfc .aspx (http://msdn.microsoft.com/en-us/library/az24scfc(VS.71).aspx)

?????? ?????????? (RegExp) ???????? (Microsoft .NET Framework ????? ?????????)
HTTP://MSDN.Microsoft.com/Library/default.asp?URL=/Library/en-us/script56/HTML/05f9ee2e-982f-4727-839e-b1b8ed696d0a.asp (http://msdn.microsoft.com/en-us/library/az24scfc(VS.71).aspx)

???? ???? ???? ??:
  • Microsoft Visual C# 2008 Express Edition
  • Microsoft Visual C# 2005
  • Microsoft Visual C# .NET 2003 Standard Edition
??????: 
kbsweptvs2008 kbhowtomaster kbsample kbmt KB308252 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:308252  (http://support.microsoft.com/kb/308252/en-us/ )