gpt4 book ai didi

java - Android将字符串分割成2个字符串

转载 作者:行者123 更新时间:2023-12-01 11:45:04 44 4
gpt4 key购买 nike

我有

字符串 s = "hello=goodmorning,2,1"

有人可以帮我编写有关如何拆分 s 使其等于以下内容的代码吗:

String s2 = "hello"
String s3 = "goodmorning"
string s4 = "2,1"

最佳答案

String s = "hello=goodmorning,2,1"

String[] str = s.split("="); //now str[0] is "hello" and str[1] is "goodmorning,2,1"

String str1 = str[0]; //hello

String[] str2 = str[1].split(","); //now str2[0] is "goodmorning" and str2[1] is "2,1"

String str3 = str2[0]; //goodmorning
String str4 = str2[1]; //2,1

输出:

str1 = hello;
str3 = goodmorning;
str4 = 2,1;

关于java - Android将字符串分割成2个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29215146/

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