如何使用objreader读取特定行 [英] How to read a specific line with objreader

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

问题描述

我正在使用objreader.readline来读取我的config.txt文件以获取信息,但我似乎无法让它读取整行。



我的代码:

I''m using objreader.readline to read my config.txt file to pull information, however I can''t seem to get it to read the whole line.

My code:

Dim FILE_NAME As String = "C:\Config.txt"

        Dim objReader As New System.IO.StreamReader(FILE_NAME)

        settings.TextBox3.Text = objReader.ReadLine(5)


        objReader.Close()





当我使用objreader.readline时( 1)它只读取第1行的字符。我希望它读取整行。



例如:



objreader.readline(3)

1.测试

2.测试

3.我希望所有这些都显示在我的文本框中。

4.测试

5.测试



我使用正确的字符串吗?



When I use objreader.readline(1) It will read only the character on line 1. I want it to read the whole line.

Example:

objreader.readline(3)
1. Test
2. Test
3. I want all of this to show in my text box.
4. Test
5. Test

Am I using the right string?

推荐答案

它实际上读了整行:

http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx [ ^ ]。



你实际上读了整行,而不是通过索引提取一个字符。难怪你得到一个角色。删除此5。 (并且不要硬编码任何东西,例如索引。)



-SA
It actually does read the whole line:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx[^].

You actually read the whole line and than extract just one character by its index. No wonder you get one character. Remove this "5". (And don''t hard-code anything, for example, indices.)

—SA


这篇关于如何使用objreader读取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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