How can I get inside parentheses value in a string?

前端 未结 10 744
半阙折子戏
半阙折子戏 2020-12-23 13:35

How can I get inside parentheses value in a string?

String str= "United Arab Emirates Dirham (AED)";

I need only AED text.

10条回答
  •  情深已故
    2020-12-23 14:12

    i can't get idea how to split inside parentheses. Would you help highly appreciated

    When you split you are using a reg-ex, therefore some chars are forbidden.

    I think what you are looking for is

    str = str.split("[\\(\\)]")[1];
    

    This would split by parenthesis. It translates into split by ( or ). you use the double \\ to escape the paranthese which is a reserved character for regular expressions.

    If you wanted to split by a . you would have to use split("\\.") to escape the dot as well.

提交回复
热议问题