我有txt文件(65mb)我需要逐行读取并更改每一行,例如我有很多行
User=value Password=value Phone=123456789
User=value Password=value Phone=123456789
User=value Password=value Phone=123456789
Run Code Online (Sandbox Code Playgroud)
我需要将第一个信用卡/手机号码更改为*(安全原因),并获取此类文本并将其保存,或者只是为了显示原始文本文件.
User=value Password=value Phone=*****6789
User=value Password=value Phone=*****6789
User=value Password=value Phone=*****6789
Run Code Online (Sandbox Code Playgroud)
我构建了新的字符串并添加到行(更改)行而不是保存,但它花了我很多时间这是我的代码
string NewPath = "";
string lineOfText;
string NewTextFile = "";
using (var filestream = new FileStream(FilePath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
{
var file = new StreamReader(filestream, Encoding.UTF8, true, 128);
while ((lineOfText = file.ReadLine()) != null)//here i reading line by line
{
NewTextFile += lineOfText.Substring(0, 124) + "************" +
lineOfText.Substring(136, lineOfText.Length - 136);
NewTextFile += Environment.NewLine;//here i make new string
} …Run Code Online (Sandbox Code Playgroud) 我使用 HtmlAgilityPack
HtmlAgilityPack.HtmlDocument DocToParse = new HtmlAgilityPack.HtmlDocument();
DocToParse.LoadHtml(HtmlIn);
HtmlAgilityPack.HtmlNode InputNode = DocToParse.GetElementbyId(IDToGet)
Run Code Online (Sandbox Code Playgroud)
这对于具有 Id like 的元素效果很好
<input type="hidden" id="nsv" value="y">
Run Code Online (Sandbox Code Playgroud)
但我需要的元素没有 Id 只有名称
<input type="hidden" name="Pass" value="106402333">
<input type="hidden" name="User" value="145">
Run Code Online (Sandbox Code Playgroud)
播种我不能使用
HtmlAgilityPack.HtmlNode InputNode = DocToParse.GetElementbyId(IDToGet)
Run Code Online (Sandbox Code Playgroud)
并且没有 GetElementbyName 方法,所以有人知道我如何通过名称获取元素吗?