Sven Ronnlund Sven Ronnlund - 1 year ago 85
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?

Answer Source

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

String name = DatabaseUtils.sqlEscapeString(name.getText().toString())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download