Cześć, zrobiłem klasę, której zadaniem jest odczytanie z pliku jakiegoś zdania (Example.txt), a następnie zastąpienie danego znaku z Example.txt znakiem ze słownika. Jeżeli tego nie tworze w klasie to wszystko działa jak należy, ale po zrobieniu mechanizmu konwertującego w klasie nie działa i nie za bardzo wiem czemu. Czy ktoś jest w stanie mi to wyjaśnić? Pliki słownika(t01t.txt) i Example.txt wrzuciłem do folderu Debug (ConsoleApp1 -> ConsoleApp1 -> bin -> Debug). Poniżej zamieszczam plik klasy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Convert
{
Dictionary<int, int> charToBr = new Dictionary<int, int>();
string line;
string convertedText = "";
bool findSignCharToBr;
int br;
public void Translate()
{
System.IO.StreamReader file = new System.IO.StreamReader(@"t01t.txt");
while ((line = file.ReadLine()) != null)
{
char[] c = new char[1];
c[0] = ' ';
string[] s = line.Split(c);
if (s.Length > 2)
{
int v1 = int.Parse(s[0], System.Globalization.NumberStyles.HexNumber);
int v2 = int.Parse(s[0], System.Globalization.NumberStyles.HexNumber);
charToBr.Add(v1, v2);
}
}
file.Close();
file = new System.IO.StreamReader(@"Example.txt");
while ((line = file.ReadLine()) != null)
{
for (int i = 0; i < line.Length; i++)
{
int x = (int)line[i];
findSignCharToBr = charToBr.TryGetValue(x, out br);
if (!findSignCharToBr)
{
Console.WriteLine("Something wrong");
break;
}
else
{
string hexValue_charToBr = br.ToString("X2");
convertedText += hexValue_charToBr + " ";
}
}
}
file.Close();
Console.WriteLine(convertedText);
}
}
}
oraz kod metody statycznej
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Convert convertChartoBr = new Convert();
convertChartoBr.Translate();
Console.ReadKey();
}
}
}