Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode a string to replace all special characters

Tags:

java

android

I have a string which contains special character. But I have to convert the string into a string without having any special character so I used Base64 But in Base64 we are using equals to symbol (=) which is a special character. But I want to convert the string into a string which will have only alphanumerical letters. Also I can't remove special character only i have to replace all the special characters to maintain unique between two different strings. How to achieve this, Which encoding will help me to achieve this?

like image 314
Sunil Kumar Sahoo Avatar asked Jan 19 '23 03:01

Sunil Kumar Sahoo


1 Answers

The simplest option would be to encode the text to binary using UTF-8, and then convert the binary back to text as hex (two characters per byte). It won't be terribly efficient, but it will just be alphanumeric.

You could use base32 instead to be a bit more efficient, but that's likely to be significantly more work, unless you can find a library which supports it out of the box. (Libraries to perform hex encoding are very common.)

like image 128
Jon Skeet Avatar answered Feb 03 '23 18:02

Jon Skeet