开发者

Splitting a String without .split command

I got a String "1/3" where I want to get only 开发者_StackOverflow社区the number 1

Is it possible to get it without using "1/3".split("\\/") ?


you can use indexOf() and subString() to get 1

String str = "1/3";
System.out.println(str.substring(0, str.indexOf("/")));  

Must See

  • Javadoc


Read the String API:

String.substring(...);


Or with some regex as well:

String s = "1/3";
String m = s.replaceAll("(\\d+)/.+", "$1");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜