gpt4 book ai didi

java - 如何识别只包含空格的字符串

转载 作者:行者123 更新时间:2023-11-30 08:15:56 24 4
gpt4 key购买 nike

<分区>

我有一个很长的字符串,我用空格字符分割它,在某些部分有多个空格,所以一个空格变成了一个字符串。我创建了一个 for 循环并尝试识别那些空格字符串以跳过它们,但不幸的是我正在使用的代码找不到它们。

public static void main( String[] args ){  


String s = "Monday Tuesday Wednesday 8:00       8:15       8:30       8:45       9:00       9:15       9:30       9:45       10:00 IT Service Mgt. F1.2 wkFeb2-wkMar23, wkApr13-wkMay11 IT Service Mgt. B180 wkFeb2-wkMar23, wkApr13-wkMay11 Strategic IT Mgt. F1.2 wkFeb2-wkMar23, wkApr13-wkMay11 10:15 10:30 10:45 11:00 Strategic IT Mgt. B145 wkFeb2-wkMar23, wkApr13-wkMay11   11:15   11:30   11:45   12:00     12:15     12:30     12:45     13:00 IT Service Mgt. B145 wkFeb2-wkMar23, wkApr13-wkMay11 IT Service Mgt. E7 wkFeb2-wkMar23, wkApr13-wkMay11   13:15   13:30   13:45   14:00   Sec. Penetration Testing B251 wkFeb2-wkMar23, wkApr13-wkMay11 Ent. Storage Sys. C129 wkFeb2-wkMar23, wkApr13-wkMay11 14:15   14:30   14:45   15:00   Ent. Storage Sys. C129 wkFeb2-wkMar23, wkApr13-wkMay11 15:15   15:30   15:45   16:00   Sec. Penetration Testing C136 wkFeb2-wkMar23, wkApr13-wkMay11 Ent. Storage Sys. C134x wkFeb2-wkMar23, wkApr13-wkMay11 16:15   16:30   16:45   17:00     17:15     17:30     17:45    ";
String[] parts = s.split(" ");
String space = " ";
for(int i=0; i<parts.length;i++)
{

if(parts[i].charAt(0) == ' ')
{
System.out.println("askdfhlghlaksjdgsdasasfasfasdfasd");
}
if(parts[i].compareTo(" ")==0){
System.out.print("asdfghgfdsaASDFGHGFDSASDFGHJKJHGFDSASDFGHJKJHGTFRD");
}
System.out.print(parts[i]);
}
}

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