-3

我使用Stringbuilder来创建这样的字符串:LS2234-32342-2342-06455。我的问题是用另一个字符串替换第 19 行“0”中的字符串。

var key = new StringBuilder { Capacity = 24 };

key.Append("L");
......

如何用其他字符串替换第 19 行?大批?

4

3 回答 3

2

If I understand correctly, you might want this;

StringBuilder sb = new StringBuilder("LS2234-32342-2342-06455");
sb.Remove(18, 1);
sb.Insert(18, 'E');
Console.WriteLine(sb.ToString());

Output will be;

LS2234-32342-2342-E6455
                  ^

Here a DEMO.

于 2013-09-16T12:39:03.727 回答
1

要替换第 19 个字符的输入,您需要访问第 18 个索引。

var sb = new StringBuilder();
sb.Append("LS2234-32342-2342-06455");

sb[18] = '0';

看:StringBuilder.Chars

于 2013-09-16T12:32:46.620 回答
0

Just use Insert you can solve this.

            StringBuilder sb = new StringBuilder();
            sb.Append("LS2234-32342-2342-06455");
            sb.Remove(18,1);
            // Insert a string to 19th position
            sb.Insert(18, "test");
于 2013-09-16T12:37:55.930 回答