将文本文件拆分为两个 [英] split a textfile in to two

查看:101
本文介绍了将文本文件拆分为两个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数百条记录的texfile。一行中的每条记录都有1250个值&值由分号分隔。在VB.NET中有一种方法可以分割每一行,例如存储在单独文本文件中的前1000个值。其余250个在另一个文本文件中。?并且同样明智的原始文本文件的每一行都以相同的方式拆分。

我想将这两个新的文本文件导入SQL Server 2表(表1包含1000列和表2包含250列)。

非常感谢你的帮助。

I have a texfile with hundreds of records. Each record in a line has 1250 values & values are seperated by a semi colon. IS there a way in VB.NET that i can split each line for example first 1000 values stored in a seperate textfile & the rest 250 in another text file.? and like wise each line of the original text file is split the same way.
I want to import these two new text files then into SQL server 2 tables ( table one with 1000 columns & table 2 with 250 columns).
many thanks for the help.

推荐答案

好吧,如果你一次读一行,那么。 />
然后您可以进行拆分并将1000放入一个文件中,将250放入另一个文件中。

或者您可以找到第1000个分号的索引并执行子串它,为文件获取两个单独的部分。


你必须小心,因为那么多的数据会耗尽内存。
Well if you read them in, one line at a time.
You can then do a split and put the 1000 into one file and 250 into another file.
Or you can find the index of the 1000th semi-colon and do a substring on it, to get the two seperate pieces for the files.

You will have to be carefull as that much data will eat up memory.


感谢Plater的回复。我如何找到第1000个分号的索引并对其进行子串?你能提供一个示例代码吗?我对vb.net很新。你对一些代码的帮助真的会让我从这里开始。谢谢。
Thanks Plater for the reply. How do I find index of the 1000th semi-colon and do a substring on it??? Can you please provide an example code. I am really new to vb.net. your help with some code will really get me started here. thanks.


好吧,如果您使用Split而不是Substring,您将获得一个字符串数组,每个字符串都是一个单独的值。那么你可以将元素0-999复制到一个文件,将元素1000复制到array.length到另一个文件。


但是确保一次执行这一行。使用 System.IO.StreamReader 为阅读。另外,使用StreamWriter进行编写。
Well, if you use Split rather than Substring, you will get an array of strings, each being a separate value. So then you could just copy elements 0-999 to one file, and elements 1000 to array.length to another.

But do make sure to do this one line at a time. Use System.IO.StreamReader for the reading. Also, use StreamWriter for the writing.


这篇关于将文本文件拆分为两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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