0
A
回答
1
看来你想在~
拆分后每2项。
这应该这样做:
Dim str = "ASD~QW~DFGH~LOP~GGGH~123~SXC~QL~"
Dim res = str.Split("~"C) _
.Select(Function(x, i) New with { x, i }) _
.Where(Function(s) s.i Mod 2 = 1) _
.Select(Function(s) s.x)
结果将是字符串的集合:"QW","LOP","123","QL"
1
这样的事情,你可能会想正则表达式。
.*?~([^~]+?)(?=~)
虽然给你的例子,String.Split可能会被按摩到工作。
这是使用正则表达式的ideone sample。
而这里的使用String.Split Split函数的版本....
Public Function Split(input As String) As List(Of String)
Dim results as List(Of String)
Dim pos = input.IndexOf("~")
If pos < 0 Then
Return New List(Of String) ' return empty list if no match
End If
input = input.Remove(0, pos)
input = input.Substring(0, input.LastIndexOf("~"))
results = input.Split("~").Where(Function(x) Not String.IsNullOrEmpty(x)).ToList()
Return results
End Function
相关问题
- 1. Vb.net获取子字符串长度
- 2. 提取字符串VB.NET
- 3. vb.net读取字符串某个字符
- 4. 当分隔符存在时获取字符串值vb.net
- 5. 获取字符串
- 6. 获取字符串
- 7. 获取字符串
- 8. 获取字符串
- 9. 获取字符串
- 10. 获取字符串
- 11. 获取字符串
- 12. 在字符串中获取字符串
- 13. 从字符串获取子字符串__
- 14. 获取字符串2个字符串
- 15. 字符串在vb.net
- 16. VB.NET - 空字符串
- 17. 字符串VS [字符串]在VB.Net
- 18. 获取字符串VB.NET中的XML部分
- 19. 获取vb.net中对象引用的字符串表示形式
- 20. 从字符串的opendialogform中获取文件名vb.net
- 21. VB.Net - 获取元素html的字符串/值?
- 22. ASP.NET + VB.NET - 如何从HTML字符串获取值
- 23. 从客户端到服务器vb.net获取实际字符串
- 24. VB.NET:从单词之间的行中获取字符串
- 25. VB.NET - 如何获取原始图像数据,以字符串
- 26. 从vb.net上的txt文件获取字符串
- 27. 通过搜索字符串获取子字符串文本来获取字符串的子字符串?
- 28. 从字符串中读取字符或从字符串中获取字符
- 29. 获取字符串的特定字符
- 30. 从字符串获取n个字符
如何在一个MsgBox显示? – mcbalaji
对于winforms:'MessageBox.Show(string.Join(“,”,res))' – Magnus
显示错误无法投射类型为'WhereEnumerableIterator'1 [VB $ AnonymousType_2'2 [System.String,System.Int32]]的对象'键入'System.String []'。 – mcbalaji