Reputation: 137
I have an Android application. When I create a new table, if I add a special character like !
or $
, 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?
Upvotes: 2
Views: 325
Reputation: 3991
You can escape special characters in a string using an inbuilt function in Android. Like below,
String name = DatabaseUtils.sqlEscapeString(name.getText().toString())
Upvotes: 3
Reputation: 4032
Use This:
String name = "Table$Name";
name = name.replaceAll("\\W", "_");
Upvotes: 3