开发者

Splitting a String without .split command

开发者 https://www.devze.com 2023-02-01 15:35 出处:网络
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

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

精彩评论

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