aspiringCoder
aspiringCoder

Reputation: 415

Is there anyway way i can trim the last "," for each array element?

 While Not sr.EndOfStream
        line = sr.ReadLine
        If line.Contains("Year") Then
            currentYear = line.ToString
        ElseIf line.Contains("mandatory") Then
            moduleStats = "M"
        ElseIf line.Contains("optional") Then
            moduleStats = "O"
        ElseIf line.Contains("COM") Then
            modArray = line.Split(",")
            Dim i As Integer = modArray.Length
            ReDim Preserve modArray(modArray.Length + 2) 'ReDim statement to change the size of one or more dimensions of an array, 
            'Preserve you can resize that dimension and still preserve all the contents of the array

            modArray(i) = moduleStats
            modArray(i + 1) = currentYear.ToString()



            MsgBox(String.Join(",", modArray))

this is my code, when i view the array in the message box it contains a comma at the end of each array element which is something i don't want any idea's how i can trim this for each element? thanks

Upvotes: 0

Views: 100

Answers (1)

Oded
Oded

Reputation: 498992

Your ReDim adds one element too many.

This causes Join to have that extra ,.

Change it to:

ReDim Preserve modArray(modArray.Length + 1)

Upvotes: 1

Related Questions