用新行分割文本框中的字符串 [英] splitting string in textbox by new line

查看:71
本文介绍了用新行分割文本框中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello friendsa,我正在vb.net中创建一个搜索页面.
在这里,用户将在多文本框中输入帐单编号(一行一行,一行中一张帐单)
这是我的代码.它可以很好地处理逗号分隔的值.
但我想逐行使用所有值.
我该怎么办.
在此先感谢朋友

hello friendsa , i am creating a search page in vb.net.
here user will enter bill no in multile textbox (line by line ,one bill in one line)
this is my code .it ias working fine for comma seprated values.
but i want to use all values line by line .
how can i do it.
Thanks in Advance friends

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim strArr() As String
        Dim itemcount As Integer
        Dim count As Integer
        Dim str As String = txtBillNo.Text
        Dim forlabel As String
        strArr = str.Split(',')
        For itemcount = 0 To strArr.Length - 1
            superTypeObj.PSearchText = strArr(itemcount)
            dsdata = superTypeObj.SearchCourierByBillno
            Dim row As DataRow = dsdata.Tables(0).Rows(0)
            count = dsSearch.Tables(0).Rows.Count
            If count <> 0 Then
                row = dsdata.Tables(0).Rows(0)
              dsSearch.Tables(0).Rows.Add(dsdata.Tables(0).Rows(0).ItemArray)
            Else
                forlabel += strArr(itemcount) & ", " & ""
            End If


        Next

        'superTypeObj.PSearchText = txtBillNo.Text

        ' dsSearch = superTypeObj.SearchCourierByBillno

        count = dsSearch.Tables(0).Rows.Count

        If count > 0 Then
            If count <= 15 Then
                Dg.PagerStyle.Visible = False
            End If
            Dg.DataSource = dsSearch
            Dg.DataBind()
            lblMsg.Text = "following" & forlabel & " Waybillnos are not correct "
        Else
            Dg.Visible = "False"

            lblMsg.Text = "following" & forlabel & " Waybillnos are not correct "
        End If
    End Sub

推荐答案

使用str.Split(vbCrLf)拆分多行文本.


除了Prera​​k的解决方案:

为了兼容,您确实应该使用System.Environment.NewLine作为分隔符.通常,使用System.StringSplitOptions.RemoveEmptyEntries很有用,请参见 http://msdn.microsoft.com /en-us/library/system.stringsplitoptions.aspx#Y19 [ ^ ]以获得代码示例.

—SA
In addition to the solution by Prerak:

For compatibility, you really should use System.Environment.NewLine for delimiter. Very often it useful to use System.StringSplitOptions.RemoveEmptyEntries, see http://msdn.microsoft.com/en-us/library/system.stringsplitoptions.aspx#Y19[^] for a code sample.

—SA


这篇关于用新行分割文本框中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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