F
F
Febel2019-02-13 13:38:12
Java
Febel, 2019-02-13 13:38:12

JAVA. How to put one parenthesis in a String?

Hello. I need to split the String exactly when the parenthesis opens.
String str = word(blabla);
I want to split the text starting from the first parenthesis and then remove the last parenthesis from substring to get only blabla from this text.
String[] pieces = str.split("(") - you can't do that unfortunately(
and then I wanted to do this:
String a = pieces[1].substring(0,pieces[1].lenght()-1)
The result should be: blabla.How
can I get blabla out of the brackets if I can't do it with split?
PS the length of word and blabla can be different

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n00ker, 2019-02-13
@Febel

@Test
    public void splitString(){
        String source = "aaaaaaaaaaa(bbbbbbbbbbbbbb(ccccc";
        String[] split = source.split("\\(");
        assertEquals(3, split.length);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question