c# - How do I change the encoding on this file? -



c# - How do I change the encoding on this file? -

i'm opening file, , reading line line. each line beingness changed, written file. need alter encoding utf-16, can't find way this. can help? is, of course, c#.

using (var inputstream = file.openread(sourcefile)) { using (var inputreader = new streamreader(inputstream)) { using (var outputwriter = file.appendtext(destfile)) { string templinevalue; while (null != (templinevalue = inputreader.readline())) { if (templinevalue != "\t\t\t\t\t") { var newendofline = string.format("{0}added info\r\0\n\0", '\0'); var firstreplace = templinevalue.replace('\t', '\0'); var secondreplace = firstreplace + newendofline; outputwriter.writeline(secondreplace); } } } } }

you can't utilize file.appendtext. based on docs: http://msdn.microsoft.com/en-us/library/system.io.file.appendtext(v=vs.110).aspx, outputs utf-8.

instead, create own streamwriter (http://msdn.microsoft.com/en-us/library/3aadshsx(v=vs.110).aspx), allow specify whatever encoding want. create new output stream , following:

var outputstream = new filestream(destfile, filemode.append, fileaccess.write); using (streamwriter outputwriter = new streamwriter(outputstream, encoding.unicode)) { //do whatever write want }

c# encoding

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -