Removing characters between single quotes. I am trying this.
If I entered sa' or '1'='1 then output should be ' or ' '='.
I am working on sql injection project. What they require is removing characters from single quotes.
By using prepared statement we can prevent injection. But before that I want to remove characters between single quotes. How to do this. Is there any easy way.
StringBuilder strBuilder = new StringBuilder();
String [] ary = uname.split("");
int j = 1;
for (int i = 0 ; i < ary.length ; i++) {
if (ary[i].equals("'")) {
if (j == 1) {
strBuilder = new StringBuilder();
strBuilder.append(ary[i]);
j++;
}
else if (j % 2 == 0) {
strBuilder.append(ary[i]);
j++;
}
else if (j % 3 == 0) {
strBuilder.append(ary[i]);
}
else if (j % 4 == 0) {
strBuilder.append(ary[i]);
break;
}
}
else {
strBuilder.append(ary[i]);
}
}
uname = strBuilder.toString();
System.out.println("uname: " + uname);