如何"Thequickbrownfoxjumps"在Java 中将字符串拆分为相同大小的子字符串.例如."Thequickbrownfoxjumps"等于4的大小应该给出输出.
["Theq","uick","brow","nfox","jump","s"]
Run Code Online (Sandbox Code Playgroud)
类似问题:
在JavaScript中,我们可以在每个第3个字符处拆分字符串
"foobarspam".match(/.{1,3}/g)
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何在Java中这样做.有什么指针吗?
我试图在网上搜索解决这个问题,但我没有找到任何东西.
我写了以下抽象代码来解释我在问什么:
String text = "how are you?";
String[] textArray= text.splitByNumber(4); //this method is what I'm asking
textArray[0]; //it contains "how "
textArray[1]; //it contains "are "
textArray[2]; //it contains "you?"
Run Code Online (Sandbox Code Playgroud)
splitByNumber方法每4个字符拆分字符串"text".我怎么能创建这个方法?
非常感谢
我有一个java字符串,它有一个可变长度.
我需要将这个片段"<br>"放入字符串中,比方说每10个字符.
例如,这是我的字符串:
`this is my string which I need to modify...I love stackoverlow:)`
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得这个字符串?:
`this is my<br> string wh<br>ich I nee<br>d to modif<br>y...I love<br> stackover<br>flow:)`
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个String阵列
String student [] = {"BAT4M0ABBB4M0ABOH4M0CCHI4U0AENG4U0DMDM4U0B"}
Run Code Online (Sandbox Code Playgroud)
我需要为每7个字符拆分一次.它应该如下所示:
String student {
"BAT4M0A",
"BBB4M0A",
"BOH4M0C",
"CHI4U0A",
"ENG4U0D",
"MDM4U0B"
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这是我的代码.
for (int i=0; i<= data.length; i++)
{
student= data[i].split(","); //data is a file of 1000 lines that is being read
if (student [2].equals(sN)) //student is a line in the each file that has been split into 11 parts
{
String timetable[]= student[9].split("(?<=\\G.......)");
System.out.println (timetable);
break;
}
Run Code Online (Sandbox Code Playgroud) 我试图分割数字,但不知道如何做到这一点.
我提到了这个链接.
假设我有一个号码12345678.
使用上面的链接我分为3个位置.所以输出变成了123 456 78.
但我想要它12 345 678并且我想采取在表单中分割的字符串 12.345.678.
有人可以帮帮我吗?