http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3326|回复: 1

[毕业生提问] 这个读写怎么会乱码啊

[复制链接]
发表于 2014-8-5 19:33:59 | 显示全部楼层 |阅读模式
1金钱
[C#] 纯文本查看 复制代码
 private void del()
        {
            string num = "";
            string str = "";
            bool yesorno;
            for (int i = 0; i < dataGridView2.RowCount; i++)
            {
                yesorno = false;
                toolStripStatusLabel10.Text = (Convert.ToInt32(toolStripStatusLabel10.Text) + 1).ToString();
                num = dataGridView2.Rows[i].Cells[0].Value.ToString();
                num = "^" + num + ".*?$";
                Regex r = new Regex(num, RegexOptions.Multiline);// 定义一个Regex对象实例
                for (int n = 0; n < dataGridView1.RowCount; n++)
                {
                    StreamReader SReader = new StreamReader(dataGridView1.Rows[n].Cells[0].Value + "\\" + dataGridView1.Rows[n].Cells[1].Value, Encoding.GetEncoding("gb2312"));
                    str = SReader.ReadToEnd();
                    SReader.Close();
                    Match m = r.Match(str);
                    if (m.Success)
                    {
                        dataGridView2.Rows[i].Cells[1].Value = "找到了:" + m.Value;
                        yesorno = true;
                        str = str.Replace(m.Value, "");
                        dataGridView2.Rows[i].Cells[1].Value = "删除了:" + m.Value;
                        FileStream fs1 = new FileStream(dataGridView1.Rows[n].Cells[0].Value + "\\" + dataGridView1.Rows[n].Cells[1].Value, FileMode.Create, FileAccess.Write);//创建写入文件 
                        StreamWriter sw = new StreamWriter(fs1);
                        sw.WriteLine(str, Encoding.GetEncoding("gb2312"));//开始写入值
                        str = "";
                        sw.Close();
                        fs1.Close();
                        toolStripStatusLabel12.Text = (Convert.ToInt32(toolStripStatusLabel12.Text) + 1).ToString();
                        break;  //跳出for循环
                    }
                }
                if (yesorno == false)
                {
                    dataGridView2.Rows[i].Cells[1].Value = "未找到:" + dataGridView2.Rows[i].Cells[0].Value.ToString();
                    toolStripStatusLabel14.Text = (Convert.ToInt32(toolStripStatusLabel14.Text) + 1).ToString();
                }
            }
        }



换了gb2312也不行

最佳答案

查看完整内容

你直接打开文件另存为看看是什么格式,应该还是编程的问题。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-8-5 19:34:00 | 显示全部楼层
你直接打开文件另存为看看是什么格式,应该还是编程的问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-1 09:03

© 2014-2021

快速回复 返回顶部 返回列表