Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divide a string into two at hyphen

I am taking a String variable from request.

String issueField = request.getParameter("issueno");

This may or may not have a hyphen in the middle. I want to be able to traverse through the String and divide the string when hyphen is seen.

like image 331
Some Java Guy Avatar asked Feb 11 '11 05:02

Some Java Guy


1 Answers

Use String#split:

String[] parts = issueField.split("-");

Then you can use parts[0] to get the first part, parts[1] for the second, ...

like image 156
Chris Kuehl Avatar answered Sep 28 '22 09:09

Chris Kuehl