我觉得解决方案非常简单,但是我现在盯着它看了10分钟,却找不出我的代码中的任何错误。真的。
而 eventDateStart
是一个整数。整数通常需要8个字符才能将字符串转换为 int
,我不明白为什么 Java 不能进行转换,我就像...唉??
代码产生 NumberFormatException 错误:
String rruleMonthday = "-1";
//where ar rrule is sth like --> RRULE:FREQ=MONTHLY;BYMONTHDAY=29
int firstMonthday = (rrule.indexOf("BYMONTHDAY=") + 11);
try {
rruleMonthday = rrule.substring(firstMonthday, rrule.indexOf(";", firstMonthday));
} catch (Exception ex) {
rruleMonthday = rrule.substring(firstMonthday, rrule.indexOf("\n", firstMonthday));
}
eventDateStart = eventDateStart.substring(0, 6) + rruleMonthday;
System.out.println("eventDateStart: ." + eventDateStart + ".");
System.out.println("2: " + Integer.parseInt(eventDateStart)); //this Integer.parseInt conversion is printing numberformatexception
输出:
eventDateStart: .20200329.
java.lang.NumberFormatException: For input string: "20200329"
eventDateStart.length()
的返回值是什么? - ProgmanSystem.out.println(eventDateStart.codePoints().mapToObj(String::valueOf).collect(Collectors.joining(",")));
将会打印什么? - Karol Dowbecki13
是回车符。尝试修剪您的字符串。 - Phil