[英]Convert Arraylist into string in vb.net
How do I convert an arraylist into a string of comma delimated values in vb.net 如何在vb.net中将arraylist转换为逗号定义的字符串
I have an arraylist with ID values 我有一个带ID值的arraylist
arr(0)=1
arr(1)=2
arr(2)=3
I want to convert it into a string 我想将其转换为字符串
Dim str as string=""
str="1,2,3"
str = string.Join(",", arr.ToArray());
If you need to convert the List to string[] before the string.Join you can do 如果你需要在string.Join之前将List转换为string [],你可以做
Array.ConvertAll<int, string>(str.ToArray(), new Converter<int, string>(Convert.ToString));
So... 所以...
str = string.Join(",", Array.ConvertAll<int, string>(str.ToArray(), new Converter<int, string>(Convert.ToString)));
作为答案,您可以尝试:
Dim s As String = String.Join(",", TryCast(arr.ToArray(GetType(String)), String()))
You can simply achieve it from GetType
and Join
Functions. 您可以从
GetType
和Join
Functions中轻松实现它。
Dim S = YourArrayList.ToArray(Type.GetType("System.String"))
MessageBox.Show(String.Join(",", S))
Another way is to use FOR EACH
Statement to read and store each item of array one by one in a delimited string. 另一种方法是使用
FOR EACH
语句在分隔的字符串中逐个读取和存储每个数组项。 (But not recommended) (但不推荐)
Dim S as string = ""
For Each item As String In YourArrayList
S &= item & ", "
Next
MessageBox.Show(S)
将String.Join与逗号分隔符一起使用( http://msdn.microsoft.com/en-us/library/57a79xd0.aspx )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.