问题
I need to create an identifier for my iOS user that is unique. Unfortunately the database that it will be saved to has a set length of 30 characters and CFUUID's are 36 (32 if removing the dashes).
Is there a way to make it into a smaller string? I think CFUUID's are hex, so would it be possible to convert it to full ASCII?
回答1:
Jeff Atwood covers this in Equipping our ASCII Armor. A Base64 encoded GUID results in 22 (24 including ==
) bytes. There are also other ascii formats you can use based on the post but Base64 will likely be the friendliest with the database server.
回答2:
First, convert your hex string to NSData using something like https://stackoverflow.com/a/7318062/382374 (be sure to strip out the "-"s). Then use something like http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php to convert the NSData to base64.
来源:https://stackoverflow.com/questions/11150516/can-i-convert-a-cfuuid-to-30-characters-or-less