Mega Code Archive

 
Categories / C# / Development Class
 

Parse GUID

using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; public class GuidUtil {     public static bool GuidTryParse(string s, out Guid result)     {         if (s == null)             throw new ArgumentNullException("s");         Regex format = new Regex(             "^[A-Fa-f0-9]{32}$|" +             "^({|\\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\\))?$|" +             "^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$");         Match match = format.Match(s);         if (match.Success)         {             result = new Guid(s);             return true;         }         else         {             result = Guid.Empty;             return false;         }     } }