Guid für Basis64 für URLC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Guid für Basis64 für URL

Post by Anonymous »

Frage: Gibt es eine bessere Möglichkeit, dies zu tun?

Code: Select all

Function GuidToBase64(ByVal guid As Guid) As String
Return Convert.ToBase64String(guid.ToByteArray).Replace("/", "-").Replace("+", "_").Replace("=", "")
End Function

Function Base64ToGuid(ByVal base64 As String) As Guid
Dim guid As Guid
base64 = base64.Replace("-", "/").Replace("_", "+") & "=="

Try
guid = New Guid(Convert.FromBase64String(base64))
Catch ex As Exception
Throw New Exception("Bad Base64 conversion to GUID", ex)
End Try

Return guid
End Function
< /code>

C#< /p>

public string GuidToBase64(Guid guid)
{
return Convert.ToBase64String(guid.ToByteArray()).Replace("/", "-").Replace("+", "_").Replace("=", "");
}

public Guid Base64ToGuid(string base64)
{
Guid guid = default(Guid);
base64 = base64.Replace("-", "/").Replace("_", "+") + "==";

try {
guid = new Guid(Convert.FromBase64String(base64));
}
catch (Exception ex) {
throw new Exception("Bad Base64 conversion to GUID", ex);
}

return guid;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post
  • Illegaler Basis64 Charakter 7b
    by Anonymous » » in Java
    0 Replies
    15 Views
    Last post by Anonymous
  • TRIM BASIS64 AUDIO -STRING mit Audiocontext
    by Anonymous » » in JavaScript
    0 Replies
    23 Views
    Last post by Anonymous
  • Wie verwende ich Guid v7 in EF Core?
    by Guest » » in C#
    0 Replies
    20 Views
    Last post by Guest
  • BLE -GUID -Unterschied zwischen Windows und Android
    by Guest » » in Android
    0 Replies
    13 Views
    Last post by Guest
  • Wie benutze ich Guid V7 im EF -Kern?
    by Guest » » in C#
    0 Replies
    14 Views
    Last post by Guest