1
The idea is to separate pieces with the split function that does not contain spaces, comma, point and comma, etc. But the function does not separate correctly, separating most of the time only space.
public String[] getTokens(String s)
{
String[] tokens;
tokens = s.split(",");
tokens = s.split(" ");
int pos = 0;
for(int i = 0; i < tokens.length; i++)
{
if(tokens[i].equals(";") || tokens[i].equals(","))
{
tokens[i] =" ";
pos = i;
break;
}
}
public void execute()
{
File[] filesArray = dt.returnFiles();
for(File f : filesArray)
{
try
{
fileContent = dt.loadFile(f);
for(int i=0; i < fileContent.size(); i++)
{
if(fileContent.get(i).equals(",") || fileContent.get(i).equals(";") ||
fileContent.get(i).isEmpty())
{
fileContent.remove(i);
}
}
Amendment!
– Alan Luz Silveira
Alan, the picture you can leave in the question, the biggest problem was not having the code in text, as it has now.
– user28595
Faith, I thought it was wrong...
– Alan Luz Silveira
The problem with your code is that you are overwriting the tokens variable after the second split. Try to pass all the characters you would like to use as a split function parameter, more or less like this:
tokens = s.split("[\\s;,]");
With this, you can divide the string by all characters.– eduardosouza
Look bro, I have the following excerpt as an example that is not working:
; Programa LOGICA.ASM

; Este programa testa todas as operacoes logicas da ALU

; Cada teste incrementa o registrador r4 se for bem sucedido.
; no final, se todos os testes forem bem sucedidos, a pontuacao
; atinge valor 10, que eh armazenada em Mem[1000]
; Cada teste verifica se a tabela verdade para a operacao
; esta sendo gerada corretamente.

zeros r4

teste0:
 zeros r0 ; Operacao C = A & B;
 zeros r1
 and r1,r0,r1
 jf.zero teste1

You know why the split is not working?– Alan Luz Silveira
Alan, you did two assignments for the variable
s
followed. Imagine that you wrote on a page of a notebook the result of the operations.split(",")
, then you ripped the page off and now (withs
intact)s.split(" ")
. Always remember that in Java strings are immutable– Jefferson Quesado