0

これは私が持っているリンクで、次の形式のデータの大きなリストが含まれています。

" X = マップ番号 : Y = マップ名 "

「10000:きのこ公園」。

vc++ .net では、そのリンクに接続し、データ内の数字 (10000 としましょう) を検索し、数字の横にある名前 (マッシュルーム パーク) を取得し、その名前を文字列。

以下のコードは私が既に持っているもので、すべてのデータが .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;}
4

1 に答える 1

1

I haven't worked with vc++ before, but I believe you're looking for the WebRequest class to get the data. Microsoft has a tutorial on making such a request. It uses a stream reader so the code inside the try block would look something like this:

String *sURL = S"http://pastebin.com/raw.php?i=yVyxkWFD";
WebRequest *wrGETURL;
wrGETURL = WebRequest::Create(sURL);
WebProxy *myProxy = new WebProxy(S"myproxy", 80);
myProxy->BypassProxyOnLocal = true;

wrGETURL->Proxy = WebProxy::GetDefaultProxy();

Stream *objStream = wrGETURL->GetResponse()->GetResponseStream();

StreamReader *MapDin = new StreamReader(objStream);

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
     }
}
于 2012-07-16T12:58:35.313 に答える