Reputation: 552
This is the link I have that contains a big list of data which has the format:
" X = MapNumber : Y = MapName "
example
" 10000: Mushroom Park ".
In vc++ .net I would want to code a function that connects to that link, searches for a number within the data (let's say 10000) and then gets the name beside the number (which would be Mushroom Park) and then put's the name into a string.
The code below is what I have already and would work if all the data was inside a .txt file but I would like to convert this code into connecting to the link above and finally making it more efficient.
Thanks.
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;}
Upvotes: 0
Views: 47
Reputation: 46
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
}
}
Upvotes: 1