开发者

How to jumble up values in a array?

I am reading a CSV while into a st开发者_运维百科ring() containing values in columns in this order like: -

"SSN", "Location", "Name", "Sex"
123456,  "IOWA",     "Jorge", "M"

But I need to jumble up the order of the columns in string() so that order should be

 "SSN", "Name", "Sex" "Location", 
123456, "Jorge", "M",   "IOWA", 

How to achieve it in Vb.net


Just create a Dictionary which you can call it later to build a string,

Dim dictionary As New Dictionary(Of String, String)
dictionary.Add("SSN", "123456")
dictionary.Add("Name", "Jorge")
dictionary.Add("Sex", "M")
dictionary.Add("Location", "IOWA")

And than later this Dictionary will help you append string for appending use string builder, Example is here,

http://www.dotnetperls.com/stringbuilder-vbnet

After every person you add clear the dictionary object and re use it for next data coming.


This is quick and dirty, but it should get you on the right track. When you are reading the string, you can put it into an array by splitting it and then re-order it.

    Dim str1 As String = "'SSN', 'Location', 'Name', 'Sex'"
    Dim str2 As String = "123456, 'IOWA', 'Jorge', 'M'"

    Dim arr1 As Array = Split(str1, ",")
    Dim arr2 As Array = Split(str2, ",")

    Dim JumbleStr1 As String = arr1(0) & ", " & arr1(2) & ", " & arr1(3) & ", " & arr1(1)
    Dim JumbleStr2 As String = arr2(0) & ", " & arr2(2) & ", " & arr2(3) & ", " & arr2(1)

This code produces:
JumbleStr1 = 'SSN', 'Name', 'Sex', 'Location'
JumbleStr2 = 123456, 'Jorge', 'M', 'IOWA'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜