Java - How to read a String after a certain character

Asked

Viewed 38 times

-1

I have a string that contains the following text "DRINKS/SODA", as I do to read only the word "SODA"?

In my code "txtDescGroup.setText(Entity.getDescGrupo1());"

Entity.getDescGroup 1() = Is what is bringing the text.

I thank anyone who can remove this silly doubt!

1 answer

0


Use split:

public class MyClass {
    public static void main(String args[]) {
        String frase = "BEBIDAS/REFRIGERANTE";
        String parts[] = frase.split("/");
        if(parts.length > 1)
        {
            System.out.println(parts[1]);    
        }
        
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.