Viennarz Valdevieso Curtiz Viennarz Valdevieso Curtiz - 4 months ago 24
Android Question

Cannot Resolve Method 'deleteCharAt()'

What is the alternative for 'deleteCharAt()'? Is there a library?

I wanted to delete a specific character on a String.

Here is my current code:

public class MainActivity extends Activity {


protected void onCreate(Bundle savedInstanceState) {

EditText name1;
EditText name2;
Button button = (Button) findViewById(;
button.setOnClickListener(new View.OnClickListener(){

public void onClick(View v){

EditText name1;
EditText name2;
TextView textout2;
TextView textout;
int sum;

name1 = (EditText)findViewById(;
name2 = (EditText)findViewById(;
int totalLength = 0;
int total;
String inputText1 = name1.getText().toString();
String inputText2 = name2.getText().toString();
totalLength = name1.length() + name2.length();

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.TOP | Gravity.LEFT,0, 0);

for (int i = 0; i < name1.length(); i++)

char ch = inputText1.charAt(i);
for (int j = 0; j < name2.length(); j++)
if (ch == inputText2.charAt(j))







Just change these lines:

StringBuilder inputText1 = new StringBuilder(name1.getText().toString());
StringBuilder inputText2 = new StringBuilder(name2.getText().toString());

StringBuilder class has a deleteCharAt() method(exactly what you are looking for).

To get a String object from StringBuilder, simply use:

String str = inputText1.toString();