regex - Replace special characters in a string with their UTF-8 encoded character java? -


i want convert special characters utf-8 equivalent character. example given string: abcds23#$_ss, should converted abcds23353695ss.

the following how did above conversion: utf-8 in hexadecimal # 23 , in decimal 35. utf-8 in hexadecimal $ 24 , in decimal 36. utf-8 in hexadecimal _ 5f , in decimal 95.

i know have string.replaceall(string regex, string replacement) method. want replace specific character specific utf-8 equivalent.

how do same in java?

i don't know how define "special characters", function should give idea:

public static string convert(string str)  {     stringbuilder buf = new stringbuilder();     (int index = 0; index < str.length(); index++)     {         char ch = str.charat(index);         if (character.isletterordigit(ch))             buf.append(ch);         else             buf.append(str.codepointat(index));     }     return buf.tostring(); }  @test public void test() {     assert.assertequals("abcds23353695ss", convert("abcds23#$_ss")); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -