English 中文(简体)
如何搜索我的文本文件? [关闭]
原标题:How to search my textfile? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers.

想要改进这个问题吗? 添加细节,并通过

Closed 10 years ago.

我希望有人能帮我一点忙,请。我有一个文本文件,有两列,每一列用一个空格分隔(“”);第一列是一个字符串,第二列是一个数字字段。

我试图在文本框1中读取数字字段,并将其与第2栏中的每个数字字段匹配,如果文本框1中的数字不大于字段,则将该行(栏1和栏2)复制到另一个文本文件中。

到目前为止,我有以下编码。

Dim l1Infos = Textbox1.text
        Select New With {.Line = l1, .Tokens = l1.Split(" "c)}
        Dim result = From l1 In l1Infos
                     Join l2 In IO.File.ReadAllLines("C:Test2",)
                     On l1.Tokens(0) Equals l2
                     Select l1.Line
        IO.File.WriteAllLines("C:Test2", result)
最佳回答

虽然尽可能多地将逻辑混为一谈可能给人留下深刻印象,并可能赢得代码模糊奖,但有时比较简单的解决办法很容易读、调试和维护:

    Dim maxValue As Integer = Integer.Parse(TextBox1.Text)
    For Each line As String In File.ReadAllLines("C:Test1")
        If Integer.Parse(line.Split(" "c)(1)) < maxValue Then
            File.AppendAllText("C:Test2", line)
        End If
    Next

我想如果这对你没有用, 就会更容易弄清楚为什么没有。 它甚至少了一条代码线!

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签