vb.net - 如何在没有逗号的情况下结束 for 循环?VB.NET
问题描述
我正要使用 for 循环从一个单元格中保存每个数字,这是我的代码:
For Each node As XmlNode In xmlnode
Dim X As String
Dim Y As String
Dim Z As String
X = node.SelectSingleNode("X").InnerText
Y = node.SelectSingleNode("Y").InnerText
Z = node.SelectSingleNode("Z").InnerText
Dim noOfPts As Integer = 0 'number of data points in data
For i As Double = 0 To noOfPts
result = X + ","
result2 = Y + ","
Next
Next
问题是我将在不保存逗号的情况下结束循环。而不是这个“1,2,3,4,5”,应该像这样“1,2,3,4,5”从循环末尾删除逗号。
解决方案
我喜欢这样做:
For i As Double = 0 To noOfPts
If result <> "" Then result &= ", "
result &= X
If result2 <> "" Then result2 &= ", "
result2 &= Y
Next
玩得开心!
推荐阅读
- eslint - eslint linting .eslintrc.js 本身
- r - 更正代码中创建的函数中参数的意外未替换
- html - 快速提问。JavaScript。我添加了一个带有 createElement 的链接,但它是不可见的
- javascript - Dropzone.js全屏dropzone不工作
- java - 显示下一个对象 OnClickListener Android Studios
- javascript - 关于带小数的数字的奇怪字符串行为
- vb.net - 从本地目录下载文件?
- javascript - 正则表达式删除除@之外的所有非字母数字
- python - 如何在snakemake中处理可变数量的复制
- amazon-web-services - AppConfig 可以用于跨账户部署吗?