Sven Ronnlund Sven Ronnlund - 4 months ago 22
Android Question

Insert special characters into table name

I have an Android application. When I create a new table, if I add a special character like

, the application crashes. I have created the functionality to replace an spaces with an
like so:

String name = name.getText().toString().replace(" ", "_");

// execute my insert query here

How can I do the same for any other special character other than space when I create a new table? Is this possible and if so, how?


You can escape special characters in a string using an inbuilt function in Android. Like below,

String name = DatabaseUtils.sqlEscapeString(name.getText().toString())