guid to base64, for URL

前端 未结 4 733
不知归路
不知归路 2020-12-04 19:20

Question: is there a better way to do that?

VB.Net

Function GuidToBase64(ByVal guid As Guid) As String
    Return Convert.ToBase64String(guid.ToByteA         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 19:48

    I understand that the reason you are clipping == in the end is that because you can be certain that for GUID (of 16 bytes), encoded string will always end with ==. So 2 characters can be saved in every conversion.

    Beside the point @Skurmedal already mentioned (should throw an exception in case of invalid string as input), I think the code you posted is just good enough.

提交回复
热议问题