如何从文本文件中读取文本 [英] How to read a text from a text file

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

问题描述

hello.i有一个文本文件,其中学生的名字出现在各个地方.有一个写着名字"的文本,然后是一个学生的名字.类似地,在另一个地方出现了这个文本名字".我要逐个获取学生的姓名,即要提取名字,然后我必须执行一些命令,然后在该命令之后我必须获取另一个名称并执行相同的命令. ....像这样,我必须继续....我的问题是,如何逐个获取学生的姓名并将其放在以vb6格式放置的文本框中.请提供详细的帮助,因为我mm对vb6中的文件读取不太熟悉.

hello.i have a text file in which the names of the sutdents occur at various placec .there is the text written "names" and then the name of one student follows it.similarlly at another place this text "Names" comes with the name of the student followed.i want to fetch the name of the student one by one i.e. first name is to be fetched then i have to do some commands then after that commands i have to fetch another name and do the same commands.....like this i have to continue....my problem is that how to fetch the name of the student one by one and put them in the text box that is placed in the vb6 form.please help in details as i mm not much familiar with file reading in vb6.

推荐答案

有很多关于使用VB6来重做/写入文件的教程.例如,参见如何阅读简单文本文件" [
There are lots of tutorials on reding/writing files with VB6. See, for instance "How to read simple text files"[^].
:)


此链接对您的要求非常有用. [ ^ ]


请按照以下步骤阅读网站根目录的Templates文件夹中存在的Template.txt文件的内容.

1.创建FileStream对象,第一个参数是文件的路径. 昏暗的fs作为新的FileStream(HttpContext.Current.Server.MapPath(〜\ Templates \ Template.txt"),FileMode.Open,FileAccess.ReadWrite,FileShare.None)
昏暗的sr作为新的StreamReader(fs)

Dim sbMailText As New StringBuilder(sr.ReadToEnd())//将文件的所有内容读入StringBuilder对象.
Please follow below steps to read the contents of the file Template.txt present in the Templates folder of the root Directory of the website.

1. create FileStream object, first parameter is the path to the file.
Dim fs As New FileStream(HttpContext.Current.Server.MapPath("~\Templates\Template.txt"), FileMode.Open, FileAccess.ReadWrite, FileShare.None)
Dim sr As New StreamReader(fs)

Dim sbMailText As New StringBuilder(sr.ReadToEnd())//Reads all the contents of the file into StringBuilder object.


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

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