首先,我在VB.net中仍然是新手,我遇到了一个奇怪的问题
我创建了一个工具,可以将多行文本框A中的内容拆分为字符串行并添加一些字符并将它们连接起来并显示在另一个多行文本框B中(A - >拆分内容 - >添加字符 - >加入 - >在B)中显示。样本就像这样
A的原始数据:
This
is
a
test
data
结果显示在B:
Row 0 = This
Row 1 = is
Row 2 = a
Row 3 = test
Row 4 = data
结果来自B:
Row 0 = This
Row 1 =
is
Row 2 =
a
Row 3 =
test
Row 4 =
data
源代码是
tempA = ""
tempB = ""
tempA = A.Text()
stringAry = tempA.Split(Environment.NewLine)
For iCounter As Integer = 0 To stringAry.Length - 1
tempB = tempB + "Row " + iCounter.ToString + " = " + stringAry(iCounter).ToString + Environment.NewLine
Next
B.Text() = tempB
所以我可以知道为什么复制的结果会与显示的结果不同,我该如何解决?
答案 0 :(得分:0)
您应该从stringAry(iCounter)
值中删除任何不需要的换行符。
tempA = ""
tempB = ""
tempA = A.Text()
stringAry = tempA.Split(Environment.NewLine)
For iCounter As Integer = 0 To stringAry.Length - 1
tempB = tempB + "Row " + iCounter.ToString + " = " + stringAry(iCounter).ToString.Replace(Environment.NewLine, string.Empty) + Environment.NewLine
Next
B.Text() = tempB