Lines are immutable - you cannot modify an existing one.
Two options:
Use StringBuilder e.g.
StringBuilder builder = new StringBuilder(new string('~', 25)); builder[5] = 'A'; string result = builder.ToString();
Create a new line from the char array:
char[] chars = new string('~', 25).ToCharArray(); chars[5] = 'A'; string result = new string(chars);
In both cases, you can fill in mutable data without creating a new line if you want - this will require more code, but will probably be more efficient.
Alternatively, you can take substrings and combine them together, according to another answer ... basically there are many ways to solve this problem. Which one is appropriate will depend on your actual use.
source share