You can like this:
var txt = "xxx xxx\r\nxxx xxx\r\nxxx xxx"; var lines = txt.Split(new string[] { "\r\n" }, StringSplitOptions.None); // заменить первую for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Remove(0, 1).Insert(0, "y"); } // заменить первую в следующем слове for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Remove(4, 1).Insert(4, "y"); } var result = string.Join("\r\n", lines);
The principle is simple. Split the file in rows, and then take the first line and look for the desired position of the desired character. Then, sorting through all the lines, delete the old character and insert a new one for this position.
Here is another example of replacing the first character in each column of each row:
var txt = "xxx xxx xxx\r\nxxx xxx xxx\r\nxxx xxx xxx"; var lines = txt.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { var columns = lines[i].Split(' '); for (int j = 0; j < columns.Length; j++) { columns[j] = columns[j].Remove(0, 1).Insert(0, "y"); } lines[i] = string.Join(" ", columns); } var result = string.Join("\r\n", lines);