简体   繁体   中英

Convert string with space separators to uint16

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!

使用LINQ

.BiosCharacteristics = (From s In test.Split(" "c) Select UInt16.Parse(s)).ToArray()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM