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","");
1

2 Answers 2

1

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

textToPass.replace(".txt","");
Sign up to request clarification or add additional context in comments.

1 Comment

thanks. Got it now. Will accept your answer after the lock releases.
0
Intent in = getIntent();
String textToPass = in.getStringExtra("textToPass");
String[] exampletext = textToPass.split("//.");

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.