Answered
Import and verify CSV data
- November 6, 2024
- 3 replies
- 2863 views
Hello everyone, I hope you are well.
I'm trying to make a code read in a CSV document, properly filled in just one column.
At first, the code is correctly reading the data, however, when checking the typed text and the data for comparison and approval, it reports as "not found".
How it works is very simple, I type the text into an Input, and use a button to check.
function processarCSV(dados:String):void
{
var linhas:Array = dados.split("\n"); // Divide o CSV em linhas
var valorDigitado:String = insert_code.text; // Valor digitado pelo usuário
var valorEncontrado:Boolean = false; // Variável para verificar se o valor foi encontrado
for (var i:int = 0; i < linhas.length; i++)
{
var colunas:Array = linhas[i].split(","); // Divide cada linha em colunas
trace("" + colunas[0]);
// Verifica se o valor digitado pelo usuário está em alguma coluna
for (var j:int = 0; j < colunas.length; j++)
{
if (colunas[j] == valorDigitado)
{
trace("Valor encontrado na linha " + (i + 1) + ", coluna " + (j + 1));
valorEncontrado = true;
break;
}
}
if (valorEncontrado) {
break; // Sair do loop de linhas se o valor foi encontrado
}
}
if (valorEncontrado) {
trace("O valor \"" + valorDigitado + "\" foi encontrado no CSV.");
} else {
trace("O valor \"" + valorDigitado + "\" não foi encontrado no CSV.");
}
}
log trace:
[SWF] teste_csv.swf - 2686 bytes after decompression
// data loaded correctly from csv
aaaa
bbbb
cccc
dddd
eeee
The value "cccc" was not found in the CSV. // When clicking the button
If you could help me, I would be very grateful.
Thank you very much in advance.
