c# - 如何从文件/ url c#中读取值
解决方案
我为你工作,我希望你能欣赏它:)
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
到空旷的地方
string reply, filter_reply;
代码:
void DownloadString(string address)
{
WebClient client = new WebClient();
reply = client.DownloadString(address);
filter_reply = reply
.Replace("using System;","")
.Replace("namespace hazedumper","")
.Replace("public static class netvars", "")
.Replace("public static class netvars", "")
.Replace("public const Int32", "")
.Replace("{", "")
.Replace("}", "")
.Replace("//", "")
.Replace("public static class signatures", "")
.Replace("timestamp = 1622802437;", "")
.Replace("2021-06-04 10:27:17.675243800 UTC", "")
.Replace("// namespace hazedumper", "")
.Replace("public const Int32 timestamp = 1622802437;","")
.Replace(" ", "")
.Replace("\n", "");
}
private static Dictionary<string, string> _extractDictionary(string str)
{
return Regex.Matches(str, "([^?=;]+)(=([^;]*))?").Cast<Match>().ToDictionary(x => x.Groups[1].Value, x => HttpUtility.UrlDecode(x.Groups[3].Value));
}
用法:
try
{
DownloadString("https://raw.githubusercontent.com/frk1/hazedumper/master/csgo.cs");
var dic = _extractDictionary(filter_reply);
foreach (var key_value in dic)
{
var key = key_value.Key;
var value = key_value.Value;
Console.WriteLine("Value of {0} is {1}", key, value);
}
}
catch (Exception ex)
{
}
推荐阅读
- c# - 当我想让至少一个复选框值为真时,如何检查 Model.IsValid 是否为真?
- django - django 中的购物车会话
- excel - HTTPRequest.SetClientCertificate
- mysql - MySQL:在输出为 CSV 格式之前在查询结果的标题上方添加文本
- logging - 如何在 Fastlane 日志中隐藏/屏蔽密码?
- angular - 角度使用 src/assets 处理大量图像,可以吗
- flutter - 退出后停止收听提供商
- ms-access - 将十进制数添加到 MS Access 查询
- css - 标题未居中对齐
- python - 将描述作为属性添加到 Pandas DataFrame 列