Read text file into string


I want to read an utf-8 encoded file into a string and use regex to match the content. I tried two methods:

The first

var file = DOpus.FSUtil.OpenFile("file.txt");
blob = file.Read();

However, I don't know how to convert blob to string.

The second

var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("file.txt", 1, false, -0);
var text = txtFile.ReadAll();

In this way, the text encoding was handled incorrectly.

var file = DOpus.FSUtil.OpenFile("D:\\Temp\\test.txt", "r"); // 无UTF8BOM的文件内容:dsvadsvdsv中文,
var Blob = file.Read();
s = DOpus.Create.StringTools.Decode(Blob, "utf-8");

StringTools (

1 Like

It works. thank you.