开发者

Dumping a Text file into a VB.net program

开发者 https://www.devze.com 2023-01-14 23:20 出处:网络
I h开发者_开发技巧ave a VB.net program that I have reading a text file, what is the best way to put the text file into VB to be able to check if a string is on one of the lines in a text file, sample

I h开发者_开发技巧ave a VB.net program that I have reading a text file, what is the best way to put the text file into VB to be able to check if a string is on one of the lines in a text file, sample code would be helpful.


Dim fileText as string = My.Computer.FileSystem.ReadAllText("c:\AnyFile.txt")

And to check whether a specific line is present in the string, use the Contains method :)

Contains method on MSDN


It might be easier to read the file as an array of strings rather then one lump string, if your doing alot of per line comparisions.

See the MSDN reference to the System.IO.File class.

http://msdn.microsoft.com/en-us/library/3saad2h5.aspx

System.IO.File.ReadAllLines

http://msdn.microsoft.com/en-us/library/s2tte0y1.aspx

Dim fileLines() as string = System.IO.File.ReadAllLines("c:\AnyFile.txt") 

Edit - woops, updated link

0

精彩评论

暂无评论...
验证码 换一张
取 消