如何将对象数组转换为双数组 [英] How do I convert an Object Array to a Double Array

查看:134
本文介绍了如何将对象数组转换为双数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,我想使用正则表达式来挑选值。我需要将生成的匹配集合传输到数组并将数据类型更改为Double。我遇到的挑战是将对象数组转换为双数组。这可能吗?如果是的话,我该如何去做?

 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(模式)
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)



是否有代码可以将mcArr的元素转换为Double并存储为新的Double数组?

解决方案


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()


这篇关于如何将对象数组转换为双数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆