Da ich momentan öfters am rum hantieren mit GUID's bin, hier eine kleine Funktion, welche eine Zeichenkette prüft ob es sich um eine gültige GUID handelt und wenn ja, diese auch liefert. Wer es braucht...
public static bool IsGuid(string s, out Guid Result)
{
bool isValidGuid = false;
Regex rxGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
Result = Guid.Empty;
if (s!= null)
{
if (rxGuid.IsMatch(s))
{
Result= new Guid(s);
isValidGuid = true;
}
}
return isValidGuid;
}