我需要在GUI应用程序中设置字符集。C#在网页上设置字符集
应用程序获取解析网页的结果并在TextBox中显示结果;
网页字符集 - Windows-1251。
我的显示器显示黑色菱形。
Thx!
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Net;
namespace WindowsFormsApplication1{
public partial class Form1 : Form{
public Form1(){
InitializeComponent();
}
private void get_field_Click(object sender, EventArgs e){
string url = url_field.Text;
string pattern = pattern_field.Text;
string html = string.Empty;
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
StreamReader result = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.GetEncoding(1251));
html = result.ReadToEnd();
MatchCollection matches = Regex.Matches(html, pattern);
foreach(Match title in matches){
GroupCollection group = title.Groups;
result_field.Text += group[1].ToString() + "\n\n\n";
}
}
}
嗯...您需要详细说明你的特定问题。我无法理解你要求的是什么。 – 2012-01-14 03:31:26
好的。我是编辑帖子,添加代码。 – systemiv 2012-01-14 03:35:04
仍然不清楚你要求的是什么。 – 2012-01-14 03:36:24