Use the regular expression [^\\s;\\\"]+\\\"[^\\\"]+\\\"
to pick up the kind of tickets <identificador>:<valor>
.
Separate <identificador>
of <valor>
with String.Split(':');
and put them in a dictionary where the key is <identificador>
and the value is <valor>
.
From the dictionary it gets easier. You can popular variables, classes, vectors,... any way you want.
In the Repl.it
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
public class Analisador
{
public static Dictionary<string,string> Parse(string entrada)
{
Dictionary<string,string> resultado =new Dictionary<string,string>();
MatchCollection matches = Regex.Matches(entrada, "[^\\s;\\\"]+\\\"[^\\\"]+\\\"");
foreach (Match match in matches)
{
string[] arr = match.Value.Split(':');
resultado.Add(arr[0], arr[1].Replace("\"", ""));
}
return resultado;
}
public static void Main()
{
Dictionary<string,string> Valores = Parse("Nome:\"João\"; Idade:\"20\"; Estado:\"SC\";");
foreach(var item in Valores)
{
Console.WriteLine($"{item.Key} = {item.Value}");
}
}
}
Is there a possibility to leave this TXT in JSON format? If yes, it would be much easier with the
Newtonsoft
– Ronaldo Araújo Alves
Ronaldo Araújo Alves, the file extension is . info but all ways to open show as if it were a txt
– Leonardo