我正在尝试逐行读取多个分隔符的文件。我使用正则表达式进行拆分,但不考虑空格("")作为分隔符。文件包含;,#,,,和空格作为分隔符。我究竟做错了什么? 文件行看起来像这样 - 添加R1,R2,R3
public static void initialize() throws IOException {
PC = 4000;
BufferedReader fileReader = new BufferedReader(new FileReader("test/ascii.txt"));
String str;
while((str = fileReader.readLine()) != null){
Instruction instruction = new Instruction();
String[] parts = str.split("[ ,:;#]");
instruction.instrAddr = String.valueOf(PC++);
System.out.println(instruction.instrAddr);
instruction.opcode = parts[0];
System.out.println(instruction.opcode);
instruction.dest = parts[1];
System.out.println(instruction.dest);
instruction.source_1 = parts[2];
System.out.println(instruction.source_1);
instruction.source_2 = parts[3];
System.out.println(instruction.source_2);
}
fileReader.close();}
输出打印4000(PC值),ADD,R1," "和R2。如何避免空间?正则表达式str.split有什么问题(" [,:;#]"); ?
答案 0 :(得分:0)
你确定那些实际上是空格吗?
这适用于任何空白区域:
<tbody>
<?php foreach ($journal_list as $journal): ?>
<tr>
<td style=""><a href="{{ url('journal/' . $journal->id) }}">{{ $journal->title }}</a></td>
@if (Auth::check())
<td style="width: 130px; overflow: hidden;">
<div class="box-button">
{{ link_to('journal/' . $journal->id . '/edit?edition=' . $edition->id, 'Edit', ['class' => 'btn btn-warning btn-sm']) }}
</div>
<div class="box-button">
{!! Form::open(['method' => 'DELETE', 'action' => ['JournalController@destroy', $journal->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger btn-sm']) !!}
{!! Form::close() !!}
</div>
</td>
@endif
</tr>
<?php endforeach ?>
</tbody>