按照合并结果文件标准调整编码
- 优先使用UTF-8读取文件以支持德语特殊字符(Ü, ü, ö等) - 输出文件使用UTF-8 with BOM格式保存 - 确保在Windows下能正确显示中文字符和特殊字符 - 完全按照'需求/合并结果/CH-875.txt'的格式标准 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
54822bd943
commit
bc6886aa24
@ -155,15 +155,15 @@ namespace SlideCombine
|
||||
try
|
||||
{
|
||||
string[] lines;
|
||||
// 先尝试UTF-8,支持特殊字符如Ü、ü等
|
||||
try
|
||||
{
|
||||
// 先尝试GBK编码,因为示例文件是中文的
|
||||
lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK"));
|
||||
lines = File.ReadAllLines(txtFile, Encoding.UTF8);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果GBK失败,再尝试UTF-8
|
||||
lines = File.ReadAllLines(txtFile, Encoding.UTF8);
|
||||
// 如果UTF-8失败,尝试GBK
|
||||
lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK"));
|
||||
}
|
||||
|
||||
foreach (var line in lines)
|
||||
@ -251,16 +251,9 @@ namespace SlideCombine
|
||||
var outputFileName = $"{result.BaseFileName}.txt";
|
||||
var outputFilePath = Path.Combine(outputPath, outputFileName);
|
||||
|
||||
// 添加BOM标记并使用ANSI编码保存
|
||||
var bom = Encoding.UTF8.GetPreamble();
|
||||
var content = Encoding.Default.GetBytes(result.OutputContent);
|
||||
|
||||
using (var fs = new FileStream(outputFilePath, FileMode.Create))
|
||||
{
|
||||
// 写入UTF-8的BOM(与示例文件一致)
|
||||
fs.Write(bom, 0, bom.Length);
|
||||
fs.Write(content, 0, content.Length);
|
||||
}
|
||||
// 使用UTF-8 with BOM保存,支持特殊字符
|
||||
var utf8WithBom = new UTF8Encoding(true);
|
||||
File.WriteAllText(outputFilePath, result.OutputContent, utf8WithBom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user