且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将对象数组转换为双数组

更新时间:2023-02-14 13:49:38


Dim re作为新的正则表达式(模式)
Dim mc作为MatchCollection
Dim mcArr()作为对象
Dim ValArr()作为Double

mc = re.Matches(ValStr )
ReDim mcArr(mc.Count-1)
mc.CopyTo(mcArr,0)



有没有代码可以放在这里转换mcArr的元素为Double并存储为一个新的Double数组?


我觉得这样的事情(与我的c#相比,我的VB很弱:

 mc = re.Matches(ValStr)
ReDim mcArr(mc.Count-1)
mc.CopyTo(mcArr, 0
ValArr = mcArr。选择功能(m) Double .Parse(m.ToString ()))。ToArray的()


I have a string that I want to pick off values using a regular expression. I need to transfer the resulting match collection to an array and change the data type to Double. The challenge I am having is converting an Object Array to a Double Array. Is this possible? If it is, how would I go about doing it?

Imports System.Text.RegularExpressions

Dim ValStr As String
ValStr = "0=1,1=4,2=3,3=2,4=7"
Dim pattern As String = "([0-9]+)(?=\,)|([0-9]+$)"
Dim re As New Regex(pattern)
Dim mc As MatchCollection
Dim mcArr() As Object
Dim ValArr() As Double

mc = re.Matches(ValStr)
ReDim mcArr(mc.Count-1)
mc.CopyTo(mcArr,0)


Is there code I can put here to convert the elements of mcArr to Double and store as a new Double Array?

)" Dim re As New Regex(pattern) Dim mc As MatchCollection Dim mcArr() As Object Dim ValArr() As Double mc = re.Matches(ValStr) ReDim mcArr(mc.Count-1) mc.CopyTo(mcArr,0)


Is there code I can put here to convert the elements of mcArr to Double and store as a new Double Array?


I think something like this (my VB is weak compared with my c#):
mc = re.Matches(ValStr)
ReDim mcArr(mc.Count-1)
mc.CopyTo(mcArr,0)
ValArr = mcArr.Select(Function(m) Double.Parse(m.ToString())).ToArray()