Search code examples
stringvb.netgroupingdivide

Dividing a string in groups of two


I have a Hex string that has a value like

26C726F026C426A1269A26AB26F026CC26E226C726E226CD

I was wondering how to split it into a string array, where each index of the array holds a group of 2 of those chars.

Example: string(0)=26,string(1)=C7,string(2) = 26,string (3) = F0, and so on. How can I do this?


Solution

  • Dim MyList as New List(Of String)
    Dim s as String = "26C726F026C426A1269A26AB26F026CC26E226C726E226CD"
    
    For x as Integer = 0 to  s.Length - 1 step 2
      MyList.Add(s.substring(x,2))
    Next
    

    You can get it with MyList(0), MyList(1) or etc