View Single Post
Old April 23rd, 2005, 04:01 PM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

This definately calls for some recursion. I don't normally provide complete solutions (unless I'm getting paid :D), but this particular challenge was interesting. Plus I tried writing out what I thought you should try, but I simply could not word it well enough. So I figured I'd just give it a go and see if I could make it work:

Dim aryJaggedData(2)() As String
aryJaggedData(0) = New String() {"Red", "Yellow", "Blue"}
aryJaggedData(1) = New String() {"8", "9"}
aryJaggedData(2) = New String() {"Covered"}

strResult = RecurseData(aryJaggedData, 0, String.Empty, String.Empty))

Private Function RecurseData(ByVal aryData As String()(), ByVal intRecurseLevel As Integer, ByVal strResult As String, ByVal strLine As String) As String
    Dim strPositionVal As String
    Dim strMyLine As String
    For i As Integer = 0 To aryData(intRecurseLevel).GetUpperBound(0)
        strPositionVal = aryData(intRecurseLevel)(i)
        If strLine.Length > 0 Then
            strMyLine = String.Format("{0}/{1}", strLine, strPositionVal)
            strMyLine = strPositionVal
        End If
        If intRecurseLevel < aryData.GetUpperBound(0) Then
            'Need to traverse down the y axis
            strResult = RecurseData(aryData, intRecurseLevel + 1, strResult, strMyLine)
            strResult = String.Format("{0}{1}{2}", strResult, Environment.NewLine, strMyLine)
        End If
    Return strResult
End Function