String Builder附加功能切断第一个字符

时间:2013-04-05 14:25:46

标签: asp.net vb.net append stringbuilder

我在这里使用带有嵌套循环的项目中的stringbuilder,而我的append语句似乎只删除了我的一个列值的第一个字符值。这是循环

For Each dr As System.Data.DataRow In gridData.Rows
            I = X.CreateElement("I")
            B.AppendChild(I)

            Dim sb As New StringBuilder

            sb.Append("|P|")
            For Each dc As DataColumn In dr.Table.Columns


                ''for ticker value, since it's a link, we need to add a character to the beginning of the value otherwise, the 1st character in
                ''in the ticker gets truncated. This was recommended by the folks at Treegrid. Only for "link" type columns. 
                ''Same goes for hhname. PD 11.11.2010
                ''Need to replace null values with space as it creates an issue on the UI with cerain browser versions in that the cell borders disappear.
                ''By placing in a blank space, it resolves any issues. Another recommendation by treegrid.
                If dc.ColumnName.ToUpper = "VCHTICKER" OrElse dc.ColumnName.ToUpper = "VCHHHNAME" Or dc.ColumnName.ToUpper = "ACNTNUM" Or dc.ColumnName.ToUpper = "STATEMENTGROUP" Or dc.ColumnName.ToUpper = "VCHSSNUMBER" Or dc.ColumnName.ToUpper = "VCHLINKLABEL" Or dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
                    If dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
                        sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", dr.Item(dc.ColumnName).ToString).ToString & "|")
                    Else
                        sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~ ", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
                    End If

                ElseIf dc.ColumnName.ToUpper = "GROUP1" Then
                    If ((dr.Item("IHHID").ToString.Length > 0) And (dr.Item("IHHID").ToString <> "0")) Then
                        sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~&nbsp;", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
                    Else
                        sb.Append(NullConvert.ToString(dr.Item(dc.ColumnName)) & "|")
                    End If
                Else

                    'sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~&nbsp;", dr.Item(dc.ColumnName)).ToString & "|")
                    sb.Append(NullConvert.ToString(dr.Item(dc.ColumnName)) & "|")
                End If

            Next dc

            Dim XMLString As String = sb.ToString.Substring(0, sb.ToString.Length - 1)
            Dim descText As XmlText = X.CreateTextNode(sb.ToString)

            I.AppendChild(descText)

            icount += 1

            If icount > Constants.MAX_RECORDS Then
                Exit For
            End If

        Next dr

我遇到的问题就在这里;

If dc.ColumnName.ToUpper = "CACCOUNTNUM" Or dc.ColumnName.ToUpper = "VCHSECURITY_SYMBOL" Then
                        sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~&nbsp;", dr.Item(dc.ColumnName).ToString).ToString & "|")
                    Else
                        sb.Append(IIf(IsDBNull(dr.Item(dc.ColumnName)), "~&nbsp;", "~" & dr.Item(dc.ColumnName).ToString).ToString & "|")
                    End If

而不是保存dr.Item的值,因为它应该像这样的“HSC01234”,它保存为“SC01234”,结尾空格和删除前导字符。在这个实例中,值永远不会为NULL,因此“〜nbsp;”不会被击中。任何帮助表示赞赏。 谢谢, NickG

1 个答案:

答案 0 :(得分:0)

我发现还有另外一个函数通过javascript播放这个值,它正在截断并修复它,谢谢你们的帮助,抱歉这个开放式问题