所以我有一個字符串military time format
:「1532」對應於3:32 pm。 我想寫一個方法來檢查時間字符串中的每個數字是否是一個合適的數字。所以第一個元素不能大於2或等於0,等等。目前,我的代碼沒有超過第二條日誌語句,我希望你們可以幫忙!如何檢查字符串中的值?
乾杯!
String mOpen = "1532";
Log.d("hoursTesting","pass1, length is > 2");
if(mOpen.getText().length() == 4)
{
Log.d("hoursTesting","pass2, length is == 4");
char[] tempString = mOpen.getText().toString().toCharArray();
if(tempString[0] != 0 && tempString[0] < 3)
{
Log.d("hoursTesting","pass3, first index is != 0 and < 3");
if(tempString[0] == 1)
{
Log.d("hoursTesting","pass4, first index is 1");
if(tempString[2] <= 5)
{
Log.d("hoursTesting","pass5, third index is <= 5, success!");
}
}
else //tempString[0] is equal to 2
{
Log.d("hoursTesting","pass4, first index is 2");
if(tempString[1] < 4)
{
Log.d("hoursTesting","pass5, second index is <3");
if(tempString[2] <= 5)
{
Log.d("hoursTesting","pass6, third index is <= 5, success!");
}
}
}
}
}
您是否嘗試過調試?如果你能直觀地看到每一步發生的事情,這可能是顯而易見的。 –
你需要支持閏秒嗎? – Jasen