gpt4 book ai didi

java - 从字符串标记器获取值

转载 作者:行者123 更新时间:2023-12-02 07:28:51 25 4
gpt4 key购买 nike

我已经编写了代码来吐出字符串,即出生日期,我想将它存储在 3 个不同的变量中,如何做到这一点。 (Mday=1,Mmonth=1,MYear=2011)。我正在动态获取生日。而且我正在获取 token 中的值。

StringTokenizer st = new StringTokenizer(BirtDate, "/");
while (st.hasMoreElements()) {
String token = st.nextToken();
System.out.println("Token = " + token);
}

最佳答案

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead

参见http://docs.oracle.com/javase/6/docs/api/java/util/StringTokenizer.html

使用代替

String[] token = BirtDate.split("/")

关于java - 从字符串标记器获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13177401/

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