0

I am using a EditText where the user enters a particular text & a FAB beside it onClick shows a Toast with the entered text...

How to replace any text after the 12345 i.e. the id value to "" ? https://www.example.com/pic?id=12345&xyz&pqr?id=0987654321/etc/etc

Any help will be appreciated

Darshan
  • 4,020
  • 2
  • 18
  • 49

1 Answers1

0

Please edit your question to be more clear, this will help others...

this is what you want

you want to get the url beffore first ampersand or remove the string, at first ampersand to end

example:

String url = "https://www.example.com/pic?id=12345&xyz&pqr?id=0987654321/etc/etc";

System.out.println(url .indexOf("&"));
System.out.println(url .substring(0,url .indexOf("&")));

//output
//36
//https://www.example.com/pic?id=12345

//what do you want

EditText editText = (EditText) findViewById(R.id.example);
editText.setText(editText.getText().toString().substring(0,editText.getText().toString().indexOf("&")));

Sources:

get index of first character with indexOf

get string form an intervale of index position

Community
  • 1
  • 1
DarckBlezzer
  • 4,578
  • 1
  • 41
  • 51