ich habe heute nach einer Möglichkeit gesucht einen String in eine Guid zu konvertieren. Dazu möchte ich eine Überprüfung haben ob die Konvertierung erfolgreich war. Dazu habe ich ein Codesnippet gefunden was ich euch nicht vorenthalten möchte:
Gefunden habe ich den Code hier: How to validate a valid GUID Value in C#
private static readonly Regex IsGuidRegEx = 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);
private static bool IsGuid(string candidate, out Guid output)
{
bool isValid = false;
output = Guid.Empty;
if (candidate != null)
if (IsGuidRegEx.IsMatch(candidate))
output = new Guid(candidate);
isValid = true;
}
return isValid;
Gruß,Volker
Achtung! Bitte Kommentar nur 1 mal absenden. Der Kommentar wird nach einiger Zeit automatisch freigegeben.Attention! Please send your comment only 1 time. The comment will be automatically published after some minutes.