数据帮助无效

我正在尝试解析我的代码,因此我可以将无效数据编辑为“数据无效”。 我无法让拆分器解决问题。

单词一 – 单词二 – 单词三 – 单词四 – 单词五有没有更简单的方法来做到这一点,而不是将每个单独的标记排序成数组。 那么“ – ”附加到一个单词的地方,我想知道如何更改它并显示类似“无效数据”的内容

只是拆分“ – ”,因为这就是数据的分离方式。 每当您在数组中获得一个空间作为索引时,您就会知道数据不包含该数据。 尝试检查数据不是空格或数据是否与数字匹配。

  while(read.hasNextLine()) { line = read.nextLine(); String[] words = line.split("-"); if(words.length == 5) { Title[counter] = words[0].matches("\\s+") ? "No Title" : words[0]; Author[counter] = words[1].matches("\\s+") ? "No Author" : words[1]; Price[counter] = !words[2].matches("\\d+") ? 0 : Integer.parseInt(words[2]); Publisher[counter] = words[3].matches("\\s+") ? "No Publisher" : words[3]; ISBN[counter] = !words[4].matches("\\d+") ? 0 : Integer.parseInt(words[4]); System.out.println(Title[counter] + Author[counter] + Price[counter] + Publisher[counter] + ISBN[counter]); counter++; } else { System.out.println("Invalid Data format: " + line); } }