如何从textfile中获取前10个字符.... [英] how to get first 10 characters from textfile ....?

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

问题描述

伙计们

问题: -

我有一个文本文件(.txt)有50行,我想要的是从文本中获取前10个字符像Mid(Content,1,10)这样的文件......

然后把它放到文本框但不带循环....



thxxxs提前

解决方案

看看:

https://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110% 29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/9kstw824(v = vs.110).aspx [ ^ ]。



-SA

我不明白你的意思是从文本文件中获取前10个字符(...)而不是循环...请看,我的评论问题。



您可以使用 File.ReadAlLines()方法 [ ^ ]。之后,您可以加入 [ ^ ]仅获取字符串使用子串方法 [ ^ ]。



  Dim  readText() As  字符串 = File.ReadAllLines(fullpathtotextfile)' 保存字符串数组中的所有行 
Dim tencharacters = 字符串 .Join( ,readText).Substring( 1 10 ' 加入所有行只能获得10个字符...







谢谢谢尔盖。你是对的 ReadAllText [ ^ ]优于<$在这种情况下,c $ c> ReadAllLines 。并且 ReadAll * 方法只有在文件不太大的情况下才有用。


hi, guys
question :-
I have one textfile (.txt) which have 50 lines, wat i want is to get first 10 characters from the text file like Mid(Content,1,10)...
and then put it to the textbox but not with loop ....

thxxxs in advance

解决方案

Take a look:
https://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx[^].

—SA


I have no idea what you mean by "get first 10 characters from the text file (...) but not with loop"... Please, see my comment to the question.

You can get all lines into string array, by using File.ReadAlLines() method[^]. After that, you can Join[^] strings to get only 10 characters by using Substring method[^].

Dim readText() As String = File.ReadAllLines(fullpathtotextfile) 'holds all lines in string array
Dim tencharacters = String.Join("", readText).Substring(1,10) 'join all lines to get only 10 characters...



[EDIT]
Thank you, Sergey. You're right ReadAllText[^] is better than ReadAllLines in this case. And ReadAll* methods are only good if the file is not too big.


这篇关于如何从textfile中获取前10个字符....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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