c# - How can I replace the string saved on the file -


i'm writing program find md5 hash has hexadecimal representation digits of pi. got problem on saving computations. looks program won't save string correctly. makes long string rather replacing old one. how can fix problem?

        public static string get_last_string()         {             string text;             string text2="";             int i= 0;             string path = "c:\\users\\uname\\desktop";             var filestream = new filestream(@path + "\\last.txt", filemode.open, fileaccess.read);             using (var streamreader = new streamreader(filestream, encoding.utf8))             {                 text = streamreader.readtoend();             }             i=0;              while (i < text.length && text[i] != ' ')             {                 text2 += text[i];                 ++i;             }             return text2;         }          public static void main(string[] args)         {              string path = @"c:\users\uname\desktop\test.txt";             string = get_last_string();             console.writeline("let continue string " + a);             console.writeline("ctrl+c stops computing , saves results file last.txt");                         {                 while (!console.keyavailable)                 {                     //                   console.writeline("md5("+a+")="+calculatemd5hash(a));                      if (commonprefix(calculatemd5hash(a), "314159265353") >= 11)                     {                          console.writeline(a + " " + calculatemd5hash(a));                         file.writealltext(path, + " " + calculatemd5hash(a));                     }                      = next(a);                 }              } while (console.readkey(true).key != consolekey.escape);             file.appendalltext(@path + "\\last.txt", a);         } 

you have file.writealltext(... , later on have file.appendalltext(... i'm pretty shure you're writing twice file.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -