C#正则问题

ert6708 2009-12-05 10:35:55
假设我采集了一个页面的N条链接,现在我想把这N条链接一条一条传到文本框(多行)中该如何去做呢?谢谢各位指教下小弟
...全文
111 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxzh0817 2009-12-06
  • 打赏
  • 举报
回复
明白了……
呵呵
MARK!
影子_爱人 2009-12-06
  • 打赏
  • 举报
回复
呵呵 跟着 学习了
mbh0210 2009-12-06
  • 打赏
  • 举报
回复
textBox3.Text = item + "\r\n";
修改为:

textBox3.Text += item + "\r\n";



gghlkk 2009-12-06
  • 打赏
  • 举报
回复

//regex=Regex.Match(pageHtml,strregex).ToString();
foreach (var item in Regex.Matches(pageHtml,strregex))
{
textBox3.Text = item.ToString() + "\r\n";
}


ert6708 2009-12-05
  • 打赏
  • 举报
回复
已近发上来,大家帮忙看下
ert6708 2009-12-05
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace FormMain
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnDefine_Click(object sender, EventArgs e)
{
int one=Convert.ToInt32(textBox1.Text);
int tow=Convert.ToInt32(textBox2.Text);
WebClient webrespen = new WebClient();
webrespen.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
byte[] pagedata = null;//用于获取指定的链接
string pageHtml = string.Empty;//接受解码后的数据
string strregex = "\\bhttp://www\\.amazon.cn/mn/detailApp/ref=sr_1_\\d+\\?_encoding=UTF8&s=books&qid=\\d+&asin=\\w+&sr=1-\\d+\\b";
string regex=string.Empty;

for (int i = one; i <=tow; i++)
{
string strurl = "http://www.amazon.cn/s/ref=?ie=UTF8&n=658490051&page=" + i.ToString();
pagedata = webrespen.DownloadData(strurl);//从指定网站下载数据
pageHtml = Encoding.UTF8.GetString(pagedata);//如果获取网站页面采用的是UTF-8,则使用这句
regex=Regex.Match(pageHtml,strregex).ToString();
foreach (string item in regex )
{
textBox3.Text = item + "\r\n";
}
}

}
}
}
ert6708 2009-12-05
  • 打赏
  • 举报
回复
使用了foreach (string link in links)
{
TextBox1.Text += link + "\r\n";
}
为何会提示无法将char类型转换为string类型呢?这个该如何解决
ert6708 2009-12-05
  • 打赏
  • 举报
回复
谢谢高手指教,我去试下
wuyi8808 2009-12-05
  • 打赏
  • 举报
回复
foreach (string link in links)
{
TextBox1.Text += link + "\r\n";
}
Mirana_NightShade 2009-12-05
  • 打赏
  • 举报
回复
up
liherun 2009-12-05
  • 打赏
  • 举报
回复
你那个n条连接放在哪里?
mbh0210 2009-12-05
  • 打赏
  • 举报
回复
贴你的代码
ert6708 2009-12-05
  • 打赏
  • 举报
回复
他说的是这个foreach不能转换
gao19892008 2009-12-05
  • 打赏
  • 举报
回复
先用 .ToString 转换下 可能你的编码有问题

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧