gpt4 book ai didi

java - 在没有 .split 命令的情况下拆分字符串

转载 作者:行者123 更新时间:2023-11-29 08:16:23 25 4
gpt4 key购买 nike

我有一个字符串“1/3”,我只想得到数字 1

不使用 "1/3".split("\\/") 是否可以得到它?

最佳答案

你可以使用 indexOf()subString() 得到 1

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

必看

关于java - 在没有 .split 命令的情况下拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4564382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com