如何在第一行的最后位置的文本文件(.txt)中附加文本 [英] How to append a text in text file(.txt) at the Last Position of First line

查看:215
本文介绍了如何在第一行的最后位置的文本文件(.txt)中附加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个文本文件(.txt).其结构如下所示

1. qwerty ^^ saasd ^^^ adadasd ^^
2. asdasdas ^^ adasdasd ^^^ asasdasd ^^
3. weqweqwew ^^^ dasdadasd ^^^ asdasd ^^^

它会相应地继续
我想通过文本框传递文本
并希望将其附加到
的最后一个位置 第一行.

让要传递的文本为1234567

这样我的新TextFile应该如下所示

1. qwerty ^^ saasd ^^^ adadasd ^^ 1234567
2. asdasdas ^^ adasdasd ^^^ asasdasd ^^
3. weqweqwew ^^^ dasdadasd ^^^ asdasd ^^^

assistant

I have created a Text File (.txt).Whose Structure is as Below

1. qwerty^^saasd^^^adadasd^^
2. asdasdas^^adasdasd^^^asasdasd^^
3. weqweqwew^^^dasdadasd^^^asdasd^^^

it goes on accordingly
I want to pass a text through a Textbox
and want it to append at the last Postion of
First line.

Let the text to be passed is 1234567

so that my new TextFile should be like as below

1. qwerty^^saasd^^^adadasd^^1234567
2. asdasdas^^adasdasd^^^asasdasd^^
3. weqweqwew^^^dasdadasd^^^asdasd^^^

assist

推荐答案

到目前为止,您尝试了什么?一种解决方案是将文本文件读入字符串数组,将文本添加到第一个数组元素,然后将字符串数组写回.


What have you tried so far? One solution is to read your text file into a string array, add your text to the first array element and then write the string array back out.

Something like
Dim lines(65535) As String
szLines = File.ReadAllLines(sourceFile)


会将文件"sourceFile"读入数组"lines"

一旦填充了行"数组,您将无法对其进行更改,因此您需要将字符串数组复制到另一个可以更改的数组中(您将在其中添加文本),然后将其写入数组到文件.

希望有帮助!


will read the file ''sourceFile'' into the array ''lines''

Once the ''lines'' array has been populated you can''t change it, so you will need to copy the string array into another one which you can change (which is where you will add your text), and then write that array to a file.

Hope that helps!


derek9999 在解决方案1中给出的那样,可以将Text读取到数组中,而无需固定数组大小. br/> Dim lines as string() = System.IO.File.ReadAllLines会做
将文本附加到第一行之后,可以使用
将这些行写回到文件中 System.IO.File.WriteAllLines方法 [
As given in Solution 1 by derek9999, the Text can be read into an array and there is no need to fix the array size.
Dim lines as string() = System.IO.File.ReadAllLines will do
After appending the text to the first line the lines can be written back to the file using the
System.IO.File.WriteAllLines Method[^]


这篇关于如何在第一行的最后位置的文本文件(.txt)中附加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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