从文件写入和读取 [英] write and read from file

查看:107
本文介绍了从文件写入和读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码来反转从textBox输入的消息,然后在另一个textBox中显示反向的结果,如何使用文件将第一个文件中的消息和其他文件打印在其中反向的结果



I have this code to reverse message entered from textBox and then show the result of reverse in another textBox ,how can using file the first file have the message and other file print in it the result of reverse

for (int i = textBox1.Text.Length - 1; i >= 0; i--)
           {
               richTextBox2.Text += '\n';
               richTextBox1.Text += textBox1.Text[i].ToString();
           }

           for (int i = 0; i <= textBox1.Text.Length - 1; i++)
           {

               richTextBox2.Text += textBox1.Text[i].ToString();
           }

推荐答案

无需使用循环。试试这个

No need to use loop. Try this
char[] arr = textBox1.Text.Trim().ToCharArray();
Array.Reverse(arr);
richTextBox2.Text = new string(arr);

< br $> b $ b

希望,它有帮助:)



更新:


使用文件读/写:



Hope, it helps :)

Update:

Using file read/write:

string text = System.IO.File.ReadAllText(@"D:\YourFolder\file1.txt");
char[] arr = text.Trim().ToCharArray();
Array.Reverse(arr);
System.IO.File.WriteAllLines(@"D:\YourFolder\file2.txt",new string(arr));


这篇关于从文件写入和读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆