i have the following string:
i need to separate each value and put it in an array. typically it would be done by “.split”. however i need it to be split in this order: 0, 50, 100, 200, 400 etc..
does anyone know how to do this? please note that i need to do this in VB
in other words, i need it to read the rows left to right. i have no problem separating each number, i just need it to read it in the specified order.
thank you all for your suggestions. ive tried the regexp and i forgot to mention that after each line there is a line break. i am not sure if this would impact the regex, but in any case, after i do the regex, i get the following order: 0, 6.65, 84..??, 35…. etc
i am not getting the order i need as stated above
expected results: 0, 50, 100, 100, 200, 400, 218, 9.8, ???, 6.65, 6.31 etc…
i am going to follow some of the suggestions below by splitting up the string into separate lines initially. this code almost does that:
Dim fields() As String
fields = calculationText.Split(vbCrLf)
unfortunately for some reason the spaces are lost. when i look into the array, all the spaces between numbers are lost. why?????????
It sounds to me like you need to split things twice. Read the file line by line into an array, or better yet a List(Of String), and then iterate through each “line” in the List and do a subsequent split based on the space.
As you go through each line, you can add the first element into your result array, list.
EDIT: Since you’re having some troubles, try out this code and see if it works for you:
This reads all of your files line per line into a List(Of String). Then from there you can do this:
That’ll split each item into an array and you can dump the first item of the split into a new List(Of String). You can easily dump this into a list of Decimals or whatever and simply wrap the CurrLine.Split around the appropriate conversion method. The rest of the items on the line will be available in the LineItems array as well.