split string to table

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

split string to table

 
0
  #1
May 7th, 2008
Erm, how to split a string using comma separated into a table? Below is my code but the output seems weird:
Lets say the row has 40 elements and 30 rows:
  1. For Count = 0 To UBound(MyArray)
  2. For a = 0 To UBound(MyArray)
  3. Dim celNew As New TableCell()
  4. 'Dim rowNew As New TableRow()
  5. 'MyArray = Split(strContents, ",")
  6. celNew.Text = MyArray(a)
  7. rowNew.Cells.Add(celNew)
  8. Table1.Rows.Add(rowNew)
  9. Next
  10. Next

Thanks.....
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: split string to table

 
0
  #2
May 7th, 2008
Can you post the output you are getting so I can try to help you ?
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

Re: split string to table

 
0
  #3
May 7th, 2008
Some how it just separate the string by comma, adding cell by cell and then repeat, look like this:


XXX XXXX XXXXX XXXXX XXXXXX
XXX XXXX XXXXX XXXXX XXXXXX
XXX XXXX XXXXX XXXXX XXXXXX
.
.
.
.
.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: split string to table

 
0
  #4
May 8th, 2008
Ok post your code and I will try to help.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 60
Reputation: evios is an unknown quantity at this point 
Solved Threads: 0
evios evios is offline Offline
Junior Poster in Training

Re: split string to table

 
0
  #5
May 9th, 2008
good...thanks first, lets say i have this randomized text file:
RFG678,1PASS,2FAILED,FGYIJUH,324,5,6,7
RF34S8,1PASS,2FAILED,FGYIJUH,324,1,6,6
.........
and i use the code below:
  1. Dim strContents As String
  2. Dim objReader As StreamReader
  3. Dim MyArray As String()
  4. Dim a As Integer
  5. Dim Count As Integer
  6. objReader = New StreamReader("C://Index4.txt")
  7. strContents = objReader.ReadToEnd()
  8. objReader.Close()
  9. For Count = 0 To 67
  10. Dim rowNew As New TableRow()
  11. MyArray = Split(strContents, ",")
  12. For a = 0 To UBound(MyArray)
  13. Dim celNew As New TableCell()
  14. 'Dim rowNew As New TableRow()
  15. 'MyArray = Split(strContents, ",")
  16. celNew.Text = MyArray(a)
  17. Label11.Text = celNew.Text
  18. rowNew.Cells.Add(celNew)
  19. Next
  20. Table1.Rows.Add(rowNew)
  21. Next

I just need to convert it into a table-like data, rows and columns separated nicely by line.
However if i using the code above, i just manage to get this:
RFG678 1PASS 2FAILED FGYIJUH 324 5 6 7 RF34S8 1PASS 2FAILED FGYIJUH 324 1 6 6

thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC