在连字符处将字符串一分为二 [英] Divide a string into two at hyphen

查看:21
本文介绍了在连字符处将字符串一分为二的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从请求中获取一个字符串变量.

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.

推荐答案

Use String#split:

Use String#split:

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

然后你可以使用parts[0]得到第一部分,parts[1]得到第二部分,...

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

这篇关于在连字符处将字符串一分为二的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆