Shishir.bobby
Shishir.bobby

Reputation: 10984

how to truncate text,android

I have a string headerText, which containing text "ABC (2-8 Days)". How can truncate text after "("? I just need text as ABC only not anything after "(" and before ")"

Many Thanks

Upvotes: 0

Views: 145

Answers (2)

om-nom-nom
om-nom-nom

Reputation: 62835

You can do this with replace regex:

String justABC = "ABC (2-8 Days)".replaceAll("\\(.*\\)","()");

The first argument of .replaceAll says that we going to match to (anything) and the second that you want to replace match with just brackets. Doubleslashes here to escape brackets.

Upvotes: 1

Elliot Bonneville
Elliot Bonneville

Reputation: 53291

This should work:

String truncText = CurrentString.split("(")[0];

I'm unfamiliar with Java so you may wind up needing to do this instead:

String[] separated = CurrentString.split("(");
String truncText = seperated[0];

Upvotes: 1

Related Questions