Convert string array to int array

后端 未结 6 1472
名媛妹妹
名媛妹妹 2021-02-04 03:42

I have tried a couple different ways and cannot seem to get the result I want using vb.net.

I have an array of strings. {\"55555 \",\"44444\", \" \"}

I need an

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 04:06

    Maybe a few more lines of code than the other answers but...

        'Example assumes the numbers you are working with are all Integers.
        Dim arrNumeric() As Integer
    
        For Each strItemInArray In YourArrayName
    
            If IsNumeric(strItemInArray) Then
    
                If arrNumeric Is Nothing Then
    
                    ReDim arrNumeric(0)
                    arrNumeric(0) = CInt(strItemInArray)
    
                Else
    
                    ReDim Preserve arrNumeric(arrNumeric.Length)
                    arrNumeric(arrNumeric.Length - 1) = CInt(strItemInArray)
    
                End If
    
            End If
    
        Next
    

提交回复
热议问题