【发布时间】:2015-04-05 23:15:23
【问题描述】:
我必须比较一个字符串是否在插入的文本框中,如果不是,它应该返回一个字符串。它不适用于下面的这行代码,有人知道吗?
if (inString.trim().length() == 0)
return "b";
这是整个代码块:
public static String checkYear(String inYear) {
// Gets the current date and time.
// Returns the actual year as an int.
Calendar now = Calendar.getInstance(); // Gets the current date and time.
int currYear = now.get(Calendar.YEAR);
try
{
int year = Integer.parseInt(inYear);
if (inYear.trim().length() == 0)
return "b";
if ((year >= 1900) && (year <= currYear))
return ""; //valid date
else
return "Year must be between 1900 and current year";
}
catch (Exception ex)
{
return "Year must be a Number";
}
}
我遇到了一个例外。
我用此代码测试文本块内是否没有任何内容:
String year = txtYear.getText();
String msgYear = DVD.checkYear(year);
int year2 = 0;
if (msgYear.length() == 1 )
{
year2 = 0;
DVD dvd2 = new DVD(txtTitle.getText(),
year2,
favouriteCheck);
dvdCollect.addDVD(dvd2);
parent.refreshDVDList();
}
【问题讨论】:
-
请提供更多代码和您希望完成的任务的完整描述,以便充分评估和解决您的问题。
标签: java string return compare