Question

Hi I need help to convert a string to array of uint16

my string look like:

Dim test as String = "4 7 9 10 11 12 14 15 16 17 19 23 24 25 26 27 28 29 30 32 33 37 40 42 48 58 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79"

And I need to convert that to a property inside my class

Public Property BiosCharacteristics As UInt16()

I've tried this:

Dim test As String = xdoc.GetAttribute(xnitem, "biosCharacteristics")
Dim stringSeparators() As String = {" "}

.BiosCharacteristics = test.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries)

I could do a For each and look for empty spaces " " but I'm looking for a more sophisticated way.

Thanks!

Was it helpful?

Solution

Use LINQ:

.BiosCharacteristics = (From s In test.Split(" "c) Select UInt16.Parse(s)).ToArray()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top