• 文章生成器,Split方法截取字符串。从硬盘读取文件,和向硬盘存储文件参考代码


            string x, y;
            private void button2_Click(object sender, EventArgs e)
            {
                textBox2.Clear();
    
                if (button4.Enabled == false)
                {
                    string[] shuzu = y.Split(new char[]{''});   //用split方法截取字符串
                    string news = "";
                    // 将截取字符串后的语句打乱顺序
    for (int i = 0; i < shuzu.Length; i++)
    {
    if (i % 2 == 0) { news += shuzu[i]+""; } else { news = shuzu[i]+"," + news; } } textBox2.Text = news; } else { MessageBox.Show("请先将当前模板存入集合"); } }

    //从硬盘读取文件

                 DialogResult isok = openFileDialog1.ShowDialog();

                 if (isok == DialogResult.OK) //判断是否点击的打开按钮

                   {  

                     string filename = openFileDialog1.FileName;//获取文件路径,文件路径存在FileName里    

                     //使用流进行文件读取

                     StreamReader sr = new StreamReader(filename);

                     //构建一个streamreader类的对象sr ,文件路径作为参数    

                     textBox1.Text = sr.ReadToEnd();  

                     //readtoend方法,把文件完全读出        

                      sr.Close();  //流用完一定关闭       

                     }

    
    
  • 相关阅读:
    iOS开发之详解剪贴板
    iOS7(Xcode5)中隐藏状态栏的方法
    如何使用iOS手势UIGestureRecognizer
    如何给列表加入搜索功能
    UITabBarController 相关
    UIButton 相关
    UINavigationController 相关
    Apple Watch 会再一次改变世界么?
    编译VLC for IOS
    ffmpeg Win8移植记(二)
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4575704.html
Copyright © 2020-2023  润新知