开发者

Vb.NET String.Format with ArrayList

开发者 https://www.devze.com 2023-01-01 14:25 出处:网络
I\'m trying to use an arraylist as the parameter to String.Format. msg = msg & String.Format(\"<td>{0}</td>\" & _

I'm trying to use an arraylist as the parameter to String.Format.

            msg = msg & String.Format("<td>{0}</td>" & _
                                      "<td>{1}</t开发者_Go百科d>" & _ 
                                      "<td>{2}</td>" & _ 
                                      "<td>{3}</td>" & _ 
                                      "<td>{4}</td>" & _ 
                                      "<td>{5}</td>" & _ 
                                      "<td>{6}</td>" & _ 
                                      "<td>{7}</td>" & _
                                      "<td>{8}</td>", param)

where param is an ArrayList and the contents are thus (copied from watch list):

+       (0) 9 {Integer} Object
+       (1) 3 {Integer} Object
+       (2) 5 {Integer} Object
+       (3) "180" {String}  Object
+       (4) 0D {Decimal}    Object
+       (5) 6.788D {Decimal}    Object
+       (6) #3/13/2009# {Date}  Object
+       (7) "2004" {String} Object
+       (8) "" {String} Object

But this code throws a FormatException

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Am I wrong that it's possible to use an arraylist? If it is possible, any clues as to why it would be throwing such an error?

Thanks


Does it accept an ArrayList?

Did you try:

 "<td>{8}</td>", param.ToArray())


You probably need to pass in an object array and not an ArrayList. If you change the code as such you may see what is going wrong:

 msg = msg & String.Format("<td>{0}</td>", param)

It should print something like

< td>System.ArrayList< td>

Have you tried this ?

 msg = msg & String.Format("<td>{0}</td>" & _
                           "<td>{1}</td>" & _ 
                           "<td>{2}</td>" & _ 
                           "<td>{3}</td>" & _ 
                           "<td>{4}</td>" & _ 
                           "<td>{5}</td>" & _ 
                           "<td>{6}</td>" & _ 
                           "<td>{7}</td>" & _
                           "<td>{8}</td>", param.ToArray())
0

精彩评论

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