C#Net 2008->;C++;翻译 所以我找到了下面的程序,我试图在C++中实现同样的结果。 请注意,这是我写的不>强,只是试图理解它,在C++中改写。< /P>
它的作用: 它在游戏RuneScape中搜索物品,并返回物品的当前价格。从表面上看,他正在使用正则表达式来寻找价格 来源: 代码:C#Net 2008->;C++;翻译 所以我找到了下面的程序,我试图在C++中实现同样的结果。 请注意,这是我写的不>强,只是试图理解它,在C++中改写。< /P>,c#,c++,.net,xml-parsing,html-parsing,C#,C++,.net,Xml Parsing,Html Parsing,它的作用: 它在游戏RuneScape中搜索物品,并返回物品的当前价格。从表面上看,他正在使用正则表达式来寻找价格 来源: 代码: using System; using System.Collections; using System.Text; using System.Net; using System.IO; using System.Text.RegularExpressions; namespace pricelookupapp { class Program { stat
using System;
using System.Collections;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace pricelookupapp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the item name to lookup prices for");
string item = Console.ReadLine();
try
{
WebClient price = new WebClient();
Stream pricestream = price.OpenRead("http://itemdb-rs.runescape.com/results.ws?query=" + item + "&sortby=name&order=1");
StreamReader priceread = new StreamReader(pricestream);
Console.WriteLine();
Console.WriteLine("Price results for " + item + ":");
string sockread = null, sockline = null;
int a = 1;
while ((sockread = priceread.ReadLine()) != null)
{
if (Regex.IsMatch(sockread, "(.*) items matched the search term: '<i>(.*)</i>'.<br>"))
{
string[] results = sockread.Split(new string[] { " " }, StringSplitOptions.None);
Console.WriteLine(results[0] + " Results Found");
}
if (Regex.IsMatch(sockread, "<td><a href=\"(.*)\"> (.*)</a></td>"))
{
sockread = nohtml(sockread);
sockline = a + " Name: " + sockread.Trim();
}
if (Regex.IsMatch(sockread, "<td>(.*)</td>"))
{
if ((!sockread.Contains("<img src") && (!sockread.Contains("<a href")) && (!sockread.Contains("<span class"))))
{
sockread = nohtml(sockread);
sockline = sockline + " Price: " + sockread.Trim();
}
}
if (Regex.IsMatch(sockread, "<td><span class=\"(.*)\">(.*)</span></td>"))
{
string[] match = Regex.Split(sockread, "<span class=\"(.*)\">");
string status = match[1], change = nohtml(sockread);
sockline = sockline + " Status: " + status + " Change: " + change;
}
if (Regex.IsMatch(sockread, "<img src=\"(.*)\" alt=\"(.*)\" title=\"(.*)"))
{
string[] match1 = Regex.Split(sockread, "title=\"(.*)\">");
string[] aa = match1[1].Split(new string[] { " " }, StringSplitOptions.None);
string type = aa[0];
type = type.Remove(type.Length - 1);
type = type.Replace("Members", "P2P");
type = type.Replace("Free", "F2P");
sockline = sockline + " Type: " + type;
Console.WriteLine(sockline);
a++;
}
}
Console.Read();
pricestream.Close();
}
catch (IOException e)
{
Console.WriteLine(e.GetType() + ": " + e.Message);
Console.Read();
}
}
public static string nohtml(string html)
{
return Regex.Replace(html, "<.*?>", "");
}
}
}
使用系统;
使用系统集合;
使用系统文本;
Net系统;
使用System.IO;
使用System.Text.RegularExpressions;
命名空间pricelookupapp
{
班级计划
{
静态void Main(字符串[]参数)
{
Console.WriteLine(“输入要查找价格的项目名称”);
string item=Console.ReadLine();
尝试
{
WebClient价格=新的WebClient();
Stream price Stream=price.OpenRead(“http://itemdb-rs.runescape.com/results.ws?query=“+项目+”&sortby=name&order=1”);
StreamReader priceread=新的StreamReader(pricestream);
Console.WriteLine();
Console.WriteLine(“项目+价格结果:”);
字符串sockread=null,sockline=null;
INTA=1;
而((sockread=priceread.ReadLine())!=null)
{
if(Regex.IsMatch(sockread,“(*)”项与搜索词匹配:“(*)。
”)
{
string[]results=sockread.Split(新字符串[]{”“},StringSplitOptions.None);
Console.WriteLine(结果[0]+“找到的结果”);
}
if(Regex.IsMatch(sockread,“”)
{
sockread=nohtml(sockread);
sockline=a+“名称:”+sockread.Trim();
}
if(Regex.IsMatch(sockread,(.*))
{
如果((!sockread.Contains((.*))
{
字符串[]匹配=Regex.Split(sockread,“”);
字符串状态=匹配[1],更改=nohtml(sockread);
插座线=插座线+“状态:”+状态+“更改:”+更改;
}
if(Regex.IsMatch(sockread,“”);
字符串[]aa=match1[1]。拆分(新字符串[]{”“},StringSplitOptions.None);
字符串类型=aa[0];
type=type.Remove(type.Length-1);
类型=类型。替换(“成员”、“对等”);
类型=类型。替换(“自由”、“F2P”);
承插线=承插线+类型:“+类型;
控制台写入线(插座线);
a++;
}
}
Console.Read();
pricestream.Close();
}
捕获(IOE异常)
{
Console.WriteLine(e.GetType()+“:”+e.Message);
Console.Read();
}
}
公共静态字符串nohtml(字符串html)
{
返回Regex.Replace(html,“,”);
}
}
}
我尝试过的:
我已经搜索了几个小时,一般来说,试图在C++中改写这个代码,我也尝试过使用卷曲——没有运气。我用C++做的事情会变得漫长而丑陋,通常不起作用。
关于要看什么库或是否有人愿意翻译它的任何建议/给我一些片段我都很乐意!添加“我尝试了什么”这句话并以“没有运气”结尾这并不能说明你在这里所尝试的一切。你完全正确。对不起,英语不是我的母语。我也不欢迎你来参加这个俱乐部。因为这是一个非常具体的问题,关于一个非常具体的问题,你不太可能得到具体的帮助。一般来说,把每一条C线翻译成可比的C++应该是B。这很简单。