191
return s.Substring(0, idx) + replaceChar.ToString() + s.Substring(idx + replaceChar.ToString().Length, s.Length - (idx + replaceChar.ToString().Length));
1
using System.Linq;
2
using System.Diagnostics;
3
using System;
4
using System.Text;
5
using System.Globalization;
6
β
7
//Created for
8
//http://metadataconsulting.blogspot.com/2019/03/A-Unicode-ReplaceAt-string-extension-method-handles-Unicode-string-properly.html
9
β
10
public static class Program
11
{
12
β
13
14
const char cEMPTY = '\0';
15
static readonly string EMPTY = cEMPTY.ToString();
16
17
public static string UnicodeReplaceAt(this string str, int offset, char replaceChar)
18
{
19
int count = 1; //number of characters to remove at location offset
20
string replaceBy = replaceChar.ToString();
21
return new StringInfo(str).ReplaceByPosition(replaceBy, offset, count).String;
22
}
23
β
24
public static StringInfo ReplaceByPosition(this StringInfo str, string replaceBy, int offset, int count)
Cached Result