gpt4 book ai didi

java - 分割字符串[]

转载 作者:行者123 更新时间:2023-12-01 16:35:36 25 4
gpt4 key购买 nike

更新:

输出应该是:

chapter: Chapter 01
title: one
code: 111111

chapter: Chapter 02
title: two
code: 222222

chapter: Chapter 03
title: three
code: 333333

chapter: Chapter 04
title: four
code: 444444

chapter: Chapter 05
title: five
code: 555555

我有这段代码来分割字符串[]。我不确定问题是什么。有人可以帮我吗?

String[] myArray = "Chapter 01<<<one<<<111111:::Chapter 02<<<two<<<222222:::Chapter 03<<<three<<<33333:::Chapter 04<<<four<<<4444:::Chapter 05<<<five<<<5555:::"

为了简单起见,我制作了虚拟String[]

for (int j = 0; j < myArray.length; j++)
{
String[] songs = myArray[j].split("\\<<<");

System.out.println("chapter: " + songs[0]);
System.out.println("title: " + songs[1]);
System.out.println("code: " + songs[2]);
}

所以我想在结果中看到的是:

chapter: Chapter 01
title: one
code: 111111
............so on and so forth........

最佳答案

public void splitString(){
String[] myArray = "Chapter 01<<<one<<<111111:::Chapter 02<<<two<<<222222:::Chapter 03<<<three<<<33333:::Chapter 04<<<four<<<4444:::Chapter 05<<<five<<<5555:::".split(":::");
for (int j = 0; j < myArray.length; j++)
{
String[] songs = myArray[j].split("<<<");

System.out.println("chapter: " + songs[0]);
System.out.println("title: " + songs[1]);
System.out.println("code: " + songs[2]);
}
}

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

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