VB.Net中的字符串连接 [英] String Concatenation in VB.Net
问题描述
嗨专家
我有一个for循环,我在执行字符串值时一直得到一个字符串值。
如何附加字符串。代码贴在下面。请提供您的解决方案。
对于 每个行作为 GridViewRow 在 gvmstrgrid.Rows
Dim chk As CheckBox = DirectCast (row.FindControl ( chkbx1),CheckBox)
如果 chk.Checked = True 那么
Dim strbr As 新 StringBuilder
Dim final As String
Dim str1 As String
str1 = DirectCast (row.FindControl( lblamc),标签)。文字
结束 如果
从上面的代码我想要连接str1并在另一个字符串中显示最终结果。
Rgds
Jagadesh
[edit]删除了主题中的喊叫并添加了代码格式。[/ edit]
我会使用字符串构建器对象来实现这个目标:
Dim s 作为 新 StringBuilder
Dim final < span class =code-keyword> As String
对于 每个行作为 GridViewRow 在 gvmstrgrid.Rows
Dim chk As CheckBox = DirectCast (row.FindControl(& quot; chkbx1& quot;),CheckBox)
如果 chk.Checked = True 然后
Dim str1 作为 字符串
str1 = DirectCast (row.FindControl( & quot; lblamc& quot;),Label)。文字
s.Append(str1)
结束 如果
下一步
final = s.ToString()
我认为会做你想做的事情。
请注意我将字符串构建器的声明和最终字符串移动到的位置。
< pre lang =vb> Dim str1 As 字符串 = 字符串 .Empty
对于 每个行作为 GridViewRow 在 gvmstrgrid.Rows
Dim chk 作为 CheckBox = DirectCast ( row.FindControl( chkbx1),CheckBox)
如果 chk.Checked = True 然后
Dim strbr As 新 StringBuilder
Dim final As 字符串
str1 & = DirectCast (row.FindControl( lblamc),Label).Text &安培; VBNewLine ' 或& ,
结束 如果
< span class =code-keyword>下一步
快乐编码!
:)
使用str1 + = DirectCast (row.FindControl( lblamc),Label).Text
最后,你会能够在str1字符串类型中找到字符串连接。
Hi Expert
I had a for loop and i am getting one string value at all the time of execuing the string value.
How to append the string. Code pasted below. Kindly provide your solutions.
For Each row As GridViewRow In gvmstrgrid.Rows
Dim chk As CheckBox = DirectCast(row.FindControl("chkbx1"), CheckBox)
If chk.Checked = True Then
Dim strbr As New StringBuilder
Dim final As String
Dim str1 As String
str1 = DirectCast(row.FindControl("lblamc"), Label).Text
End If
From the above code i want the str1 to be concatenate and show the final result in another string.
Rgds
Jagadesh
[edit]Removed shouting in subject and added code formatting.[/edit]
I would use a string builder object to achieve this:
Dim s As New StringBuilder Dim final As String For Each row As GridViewRow In gvmstrgrid.Rows Dim chk As CheckBox = DirectCast(row.FindControl("chkbx1"), CheckBox) If chk.Checked = True Then Dim str1 As String str1 = DirectCast(row.FindControl("lblamc"), Label).Text s.Append(str1) End If Next final = s.ToString()
Something like that I believe will do what you are after.
Please note where I moved your declarations of the string builder and the final string to.
Dim str1 As String = string.Empty For Each row As GridViewRow In gvmstrgrid.Rows Dim chk As CheckBox = DirectCast(row.FindControl("chkbx1"), CheckBox) If chk.Checked = True Then Dim strbr As New StringBuilder Dim final As String str1 &= DirectCast(row.FindControl("lblamc"), Label).Text & VBNewLine 'or & ", " End If Next
Happy Coding!
:)
usestr1 += DirectCast(row.FindControl("lblamc"), Label).Text
and finally, you will be able to find string concatanation in thisstr1string type.
这篇关于VB.Net中的字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!