我需要循环遍历数组并以下列方式填充字符串
首先 - > string = array(0)+ array(1)+ array(2)
然后 - > string = array(1)+ array(2)
然后 - > string = array(2)
如果数组的长度是动态的,我该如何实现?我正在使用vb.net谢谢!
您可以使用2个for
循环来完成此任务。第一个for
循环将循环遍历整个数组,发送循环将循环遍历要添加到字符串的数组部分。
var tempList = new ArrayList();
tempList.Add("Test1");
tempList.Add("Test2");
tempList.Add("Test3");
var tempString = new System.Text.StringBuilder();
for (int i = 0; i < tempList.Count; i++)
{
for (int j = i; j < tempList.Count; j++)
{
tempString.Append(tempList[j]);
}
}