-2
我正在轉換VB應用程序。我正在嘗試使用StringBuilder創建一個字符串,因爲我無法使用Mid函數更改字符串。我有一個循環,雖然它只是將第一個字符添加到字符串,其餘的只是空白。我如何將所有數據添加到字符串?在C#中使用StringBuilder創建字符串
下面的代碼片段;感謝您的幫助
int table = 0;
string tableData = Strings.StrDup(253, " ");
int i = 0;
string listData = null;
int pointer =0;
StringBuilder sb = new StringBuilder(tableData);
sb.Insert(0, Strings.StrDup(253, Strings.Chr(32)));
sb.Insert(0, typeOfTable + Strings.Chr(0));
pointer = 2;
for (i = 0; i <= lstTABLE.Items.Count -1; i++)
{
listData = lstTABLE.Items[i].ToString();
table = Convert.ToInt32(-(Conversion.Val(listData) * 10));
sb.Insert(pointer, Functions.FNCodeTwoChar(table));
pointer +=2;
}
sb.Insert (202,Functions.EncodeKP(Convert.ToSingle(Conversion.Val(lblStartTable.Text))));
sb.Insert(205,Functions.EncodeKP(Convert.ToSingle(Conversion.Val(lblEndTable.Text))));
sb.Insert(208, Strings.Space(36));
sb.Insert(244, " 0");
sb.Insert(248, " 0");
問題是? –
爲什麼你使用'StringBuilder.Insert',要求你管理愚蠢的字符指針?使用['StringBuilder.Append'](https://msdn.microsoft.com/en-us/library/system.text.stringbuilder.append.aspx)! – poke
謝謝,但沒有必要投票 – Russ