在 vb.net 中重新格式化大文本文件

发布于 2024-12-20 15:28:56 字数 699 浏览 1 评论 0原文

我面临一个相当大的文本文件(200-400 行)

该文件显示大量数据,但问题是它没有排列。 目前的数据类似于此

Column1    Column2    Column3    Column4
Bobby      Fisher    Virginia    Rural
Willis     Johnson    Oklahoma    City
Ryan       Polk    Nevada    Suburban
Bruno      Garfield   Orgeon    Rural

文件在每个条目之间使用一定数量的空格,这会导致问题。 有没有办法可以打破这个问题,并为每个单词允许 X 个空格,如果较短,请用空格填充空格?

我目前唯一的想法是从文本文件中提取每一行,然后提取每个单词。

有没有更简单的方法,或者我只是陷入了困境?

大多数人都能猜到最终产品会是什么样子,但它就是这样

Column1    Column2    Column3    Column4
Bobby      Fisher     Virginia   Rural
Willis     Johnson    Oklahoma   City
Ryan       Polk       Nevada     Suburban
Bruno      Garfield   Orgeon     Rural

I am faced with a rather large text file (200-400 lines)

The file displays a lot of data however the problem is that it is not lined up.
The data at the moment resembles this

Column1    Column2    Column3    Column4
Bobby      Fisher    Virginia    Rural
Willis     Johnson    Oklahoma    City
Ryan       Polk    Nevada    Suburban
Bruno      Garfield   Orgeon    Rural

The file uses a set number of spaces between each entry, which causes the problem.
Is there a way to possible break this up and for each word allow X amount of spaces, and if it is shorter fill in the space with spaces?

My only thought at the moment would be to pull each line from the text file and then pull each word.

Is there an easier way or am I just in a pretty big pickle?

Most of you all can guess what the end product will look like but here it is

Column1    Column2    Column3    Column4
Bobby      Fisher     Virginia   Rural
Willis     Johnson    Oklahoma   City
Ryan       Polk       Nevada     Suburban
Bruno      Garfield   Orgeon     Rural

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦旅人picnic 2024-12-27 15:28:56

这能满足您的需要吗?

Array.ConvertAll(lines, _
    Function(cells) _
        String.Concat( _
            Array.ConvertAll(cells.Split(), Function(s) s.Trim().PadRight(40))))

Does this do what you need?

Array.ConvertAll(lines, _
    Function(cells) _
        String.Concat( _
            Array.ConvertAll(cells.Split(), Function(s) s.Trim().PadRight(40))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文