Я хотел бы получить string
, начинающийся с другой string
(что я должен исправить это) я использовал следующие коды, но я также string
, который начинается с другой string
, что я Wouldn Мне нравится!как проверить, что строка начинается с другой строкой в Java
if (critere.equals("Date")) {
String date = jTextField5.getText();
try {
FileInputStream file = new FileInputStream(new File(jTextField1.getText()));
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
for (Row row : sheet) {
for (Cell cell : row) {
/* SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date d = dateFormat.parse(cell.getRichStringCellValue().getString());
SimpleDateFormat printFormat1 = new SimpleDateFormat("MM/dd/yyyy");
Date dd = printFormat1.parse(printFormat1.format(d));*/
if (cell.getRichStringCellValue().getString().trim().startsWith(date)) {// I have problem here
CellReference ref = new CellReference("A1");
CellReference ref1 = new CellReference("B1");
CellReference ref2 = new CellReference("C1");
CellReference ref3 = new CellReference("D1");
CellReference ref4 = new CellReference("E1");
CellReference ref5 = new CellReference("G1");
CellReference ref6 = new CellReference("I1");
CellReference ref7 = new CellReference("J1");
Cell c = row.getCell(ref.getCol());
Cell c1 = row.getCell(ref1.getCol());
Cell c2 = row.getCell(ref2.getCol());
Cell c3 = row.getCell(ref3.getCol());
Cell c4 = row.getCell(ref4.getCol());
Cell c5 = row.getCell(ref5.getCol());
Cell c6 = row.getCell(ref6.getCol());
Cell c7 = row.getCell(ref7.getCol());
if (c.getStringCellValue().equals("Warning")) {
((DefaultTableModel) jTable1.getModel()).addRow(new Object[]{c.getStringCellValue(), c1.getStringCellValue(), c2.getStringCellValue(),
c3.getStringCellValue(), c4.getStringCellValue(), c5.getStringCellValue(), c6.getStringCellValue(), c7.getStringCellValue()});
}
if (c.getStringCellValue().equals("Minor")) {
((DefaultTableModel) jTable2.getModel()).addRow(new Object[]{c.getStringCellValue(), c1.getStringCellValue(), c2.getStringCellValue(),
c3.getStringCellValue(), c4.getStringCellValue(), c5.getStringCellValue(), c6.getStringCellValue(), c7.getStringCellValue()});
}
if (c.getStringCellValue().equals("Major")) {
((DefaultTableModel) jTable3.getModel()).addRow(new Object[]{c.getStringCellValue(), c1.getStringCellValue(), c2.getStringCellValue(),
c3.getStringCellValue(), c4.getStringCellValue(), c5.getStringCellValue(), c6.getStringCellValue(), c7.getStringCellValue()});
}
if (c.getStringCellValue().equals("Critical")) {
((DefaultTableModel) jTable4.getModel()).addRow(new Object[]{c.getStringCellValue(), c1.getStringCellValue(), c2.getStringCellValue(),
c3.getStringCellValue(), c4.getStringCellValue(), c5.getStringCellValue(), c6.getStringCellValue(), c7.getStringCellValue()});
}
}
}
}
Я хотел бы войти в этот букле, когда дата начинается с даты, что я должен войти в моем приложении в качестве входных данных, но когда я запускаю мое приложение, что войти в этот букле даже дата не начинается с значение, которое я ввести
Неясно, что вы говорите. Можете ли вы привести пример? – SMA
Пожалуйста, покажите короткую, но полную программу, которая демонстрирует проблему. Мы не знаем, что возвращает 'getString()', или что такое 'date'. –
проверить обновленный пост – jiji