0

How do you replace strings when you retrieve a data from an activity ? I cant seems to find it google. Maybe my question is too simple. Please see the below codes.

Intent in = getIntent();
textToPass = in.getStringExtra("textToPass");

textToPass is actually a string eg. "ExampleText.txt"

How do you remove the .txt to make it look like "ExampleText"

I might be somewhere near, but I still couldnt figure out

String exampletext = textToPass.getText().toString().replace(".txt","");
KC Chai
  • 1,597
  • 9
  • 27
  • 59

2 Answers2

1

Here textToPass is string so you can directly apply replace method on it .

textToPass.replace(".txt","");
Chirag
  • 56,384
  • 29
  • 154
  • 197
0
Intent in = getIntent();
String textToPass = in.getStringExtra("textToPass");
String[] exampletext = textToPass.split("//.");

Then use exampletext[0] it must give your expectation result

No_Rulz
  • 2,684
  • 1
  • 17
  • 32