如何从文件/ url c#中读取值
Posted
技术标签:
【中文标题】如何从文件/ url c#中读取值【英文标题】:How to read values from file/url c# [closed] 【发布时间】:2021-08-25 07:51:43 【问题描述】:我想从 here 获取值并在我的 c# 控制台应用程序中使用它们。我已经知道如何将所有这些写入一个单独的文件,但我不知道如何从文件/url 中读取值。
欢迎任何帮助!
【问题讨论】:
发帖前请先搜索:***.com/questions/1048199/… 【参考方案1】:我为你工作,希望你能欣赏它:)
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)
【讨论】:
你能告诉我结果吗以上是关于如何从文件/ url c#中读取值的主要内容,如果未能解决你的问题,请参考以下文章
如何从 URL 读取 Windows 应用程序中的大量 xml 文件(从 Windows 应用程序到服务器的多个请求)c#