我有一个 ~7mb 的文本文件,我想从中提取一些信息,它包含许多类似格式的实例:
"name": "Riki's Dagger",
"defindex": 0,
"item_class": "dota_item_wearable",
"item_type_name": "#DOTA_WearableType_Daggers",
"item_name": "#DOTA_Item_Rikis_Dagger",
"proper_name": false,
"item_quality": 0,
"image_inventory": null,
"min_ilevel": 1,
"max_ilevel": 1,
"image_url": "",
"image_url_large": "",
我想提取名称和定义索引,检查此实例是否包含/不包含某些关键字,然后将其放入新的文本文件中,以便以后使用。我的计划是在文件中搜索“name”的每个实例(带引号),并将下一个“name”实例之前的所有内容设置为一个名为 current 的变量。然后从那里搜索当前字符串以获取我需要的信息。这是最好的方法吗?我该怎么做?我应该使用正则表达式还是文件太大?一些方向将不胜感激。
这是我到目前为止所拥有的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
namespace ConsoleApplication1
{
class Test
{
static void Main(string[] args)
{
string ingameschemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\ingameschema.txt";
string dota2schemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\dota2schema.txt";
string schemaFilePath = @"C:\Users\Andrew\Documents\GitHub\SteamBot\Bin\Debug\schema.txt";
string[] ingameschema = File.ReadAllLines(ingameschemaFilePath);
string[] dota2schema = File.ReadAllLines(dota2schemaFilePath);
string[] current = null;
string[] name = null;
string[] defindex = null;
string[] rarity = null;
using (TextWriter textWriter = new StreamWriter(schemaFilePath))
{
foreach (//search for "name"->"name" segment here)
{
// if current.Contains("dota_item_wearable") == false, current.Contains("announcer", "courier", "ward", "egg", "costume", "HUD", "smeevil", "taunt", "bait", "lure", "bundle" ) == true,
// break
}
}
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}