如何忽略带符号的某些行(ASP.net中的VB.net) [英] How to ignore certain lines with symbols(VB.net in ASP.net)

查看:52
本文介绍了如何忽略带符号的某些行(ASP.net中的VB.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,我读到ASP.net网站。



 ********* ************************************************** *** 
*注意不要删除符号,例如= *#!
*
*
************************************ **************************

#读取这个
!忽略这个





所以这是文本文件。我想只阅读以#开头的行并忽略其余部分。



任何帮助都将不胜感激。



一直试用代码几天仍然找不到任何解决方案。谢谢!



'受保护的子PerformButton_Click(ByVal sender As Object,ByVal e As EventArgs)处理PerformButton.Click 
'SourceTextBox。 Text()=
'TargetTextBox.Text()=
'Dim path As String = TextFileUpload.PostedFile.FileName
'Dim sw As StreamReader = New StreamReader(path)
'对于每个
'如果sw.ReadLine()。StartsWith(#)那么
'TextBox1.Text =
'结束如果

解决方案

试试这个:



< br /> 
var lines = System.IO.File.ReadAllLines(TextFileUpload.PostedFile.FileName)< br />
.Where(x => x.StartsWith(#))< br />
.ToList();< br />


 受保护的  Sub  PerformButton_Click( ByVal 发​​件人作为 对象 ByVal  e  As  EventArgs)句柄 PerformButton.Click 
Dim 路径作为 字符串 = TextFileUpload.PostedFile.FileName
< span class =code-keyword> Dim readText()作为 字符串 =文件。 ReadAllLines(path)
Dim strbuild = StringBuilder()
Dim s 作为 字符串
对于 每个 s readText
如果 s.Trim.StartsWith( 然后
SourceTextBox.Text = s.TrimStart(
结束 如果
如果 s.Trim.StartsWith( 然后
TargetTextBox.Text = s.TrimStart(
结束 如果

下一步

结束


I have a text file that I read in to an ASP.net website.

**************************************************************
*Notes do not remove symbols e.g. = *#!	
*
*
**************************************************************

#Read this
!Ignore This



So this is the text file. I want to read only the lines that start with # and ignore the rest.

Any help would be appreciated.

Been trying out code for days and still couldn't find any solutions. Thanks!

'Protected Sub PerformButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PerformButton.Click
    '    SourceTextBox.Text() = ""
    '    TargetTextBox.Text() = ""
    '    Dim path As String = TextFileUpload.PostedFile.FileName
    '    Dim sw As StreamReader = New StreamReader(path)
    '    For Each 
    '        If sw.ReadLine().StartsWith("#") Then
    '            TextBox1.Text = 
    '        End If

解决方案

Try this:

 <br />
var lines = System.IO.File.ReadAllLines(TextFileUpload.PostedFile.FileName)<br />
                .Where(x=>x.StartsWith("#"))<br />
                .ToList();<br />


Protected Sub PerformButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PerformButton.Click
        Dim path As String = TextFileUpload.PostedFile.FileName
        Dim readText() As String = File.ReadAllLines(path)
        Dim strbuild = New StringBuilder()
        Dim s As String
        For Each s In readText
            If s.Trim.StartsWith("#") Then
                SourceTextBox.Text = s.TrimStart("#")
            End If
            If s.Trim.StartsWith("!") Then
                TargetTextBox.Text = s.TrimStart("!")
            End If

        Next
        
    End Sub


这篇关于如何忽略带符号的某些行(ASP.net中的VB.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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