Change file encoding

  • Автор темы Автор темы qlwik
  • Дата начала Дата начала

qlwik

Client
Регистрация
03.04.2013
Сообщения
208
Реакции
5
Баллы
18
Hi, is there any way to convert any file for example from windows-1251 to utf-8 with zennoposter, for example with C#? windows-1251 is only example, this might be different encoding, just don't suggest me notepad++, it must be integrated in template.
 
Ok I got below code from stackoverflow:

C#:
Развернуть Свернуть Копировать
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string inputFile = @"C:\file.txt";      // Path to your input file
        string outputFile = @"C:\file2.txt";   // Path to your output file
        
        ConvertEncoding(inputFile, outputFile);
        
        Console.WriteLine("Conversion complete.");
    }

    static void ConvertEncoding(string inputFilePath, string outputFilePath)
    {
        using (StreamReader reader = new StreamReader(inputFilePath, Encoding.GetEncoding("iso-8859-1")))
        {
            using (StreamWriter writer = new StreamWriter(outputFilePath, false, Encoding.UTF8))
            {
                writer.Write(reader.ReadToEnd());
            }
        }
    }
}

But it throw a lot of errors, for example:
Compiling code of Error in action "CS1003" "Syntax error, '(' expected". [Row: 1; Column: 7]
What is wrong?
 
You can not just copy any code anywhere and expect it to work, man.
You need to change it as per your requirements.
This is the code needed for you, but you still have to change variables to yours.
I have not tested though.

C#:
Развернуть Свернуть Копировать
using (StreamReader reader = new StreamReader(inputFilePath, Encoding.GetEncoding("iso-8859-1")))
{
    using (StreamWriter writer = new StreamWriter(outputFilePath, false, Encoding.UTF8))
    {
        writer.Write(reader.ReadToEnd());
    }
}
 
I saw Your code, but I don't know how to insert input and output files to code, because I don't know C#, can You help me?
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)