这是我拥有的链接,其中包含大量数据,其格式如下:
“ X = 地图编号:Y = 地图名称”
例子
《10000:蘑菇园》。
在 vc++ .net 中,我想编写一个连接到该链接的函数,在数据中搜索一个数字(比如说 10000),然后获取数字旁边的名称(这将是 Mushroom Park),然后将名称放入一个字符串。
下面的代码是我已经拥有的,如果所有数据都在一个 .txt 文件中,它将起作用,但我想将此代码转换为连接到上面的链接并最终使其更高效。
谢谢。
String^ GrabMapNameById(String^ CurrentStr)//Current Map String{
if(CurrentMapIDRead.ToString() != CurrentMapID.ToString()) //If map has chnaged
{
try //Try streaming text
{
String^ Maps = "Strife.Maps";//map File Name
StreamReader^ MapDin = File::OpenText("Strife.Maps");//Stream Declar
String^ str;
string s;
int count = 0;
while ((str = MapDin->ReadLine()) != nullptr) //Loop for every line
{
if(str->Contains(CurrentMapID.ToString())) //Untill Map id found
{
CurrentMapIDRead = CurrentMapID; //Set Current Map Name
CurrentStr = str->Replace(CurrentMapIDRead.ToString() , "" );//Replace map id with null characters
CurrentStr = CurrentStr->Replace(" =" , "" ); //Take out = characters
break;// kill while
}
}
}
catch (Exception^ e)
{
}
}return CurrentStr;}