Question: I am trying to send "{" and "}" using `SendKeys.Send()`

I already tried to use `string.Replace{"{", "{{}"}`

```cs
txt = txt.Replace("{", "{{}");
txt = txt.Replace("}", "{}}");
SendKeys.Send(txt);

```

I expected it to send "{" and "}" but the Program throws an error 

> 
> System.FormatException
> 
> 
>

Answer: 
As others have pointed out your second `Replace`, replaces the curly braces added by your first `Replace`.

To escape the curly braces within a string you could use `Regex` like this:
`SendKeys.Send(Regex.Replace(txt, @"[/{/}]", m => string.Format("{{{0}}}", m.Value)));`

Or even better escape all characters that have special meaning in this context ie. `Regex.Replace(txt, @"[/{/}/+/%/~/(/)]", m => string.Format("{{{0}}}", m.Value))`

Another completely different option would be to send characters one at the time and escape curly braces when necessary:

```
"some{}text".ToCharArray().ToList()
   .ForEach(a=> SendKeys.Send(a == '}' || a == '{' ? "{"+a+"}": a.ToString()));

```
`{` has to be escaped by `{{}`. `}` has to be escaped by `{}}`. This attempt to escape ...

```
// NON-WORKING EXAMPLE!
txt = txt.Replace("{", "{{}");
txt = txt.Replace("}", "{}}");

```

... has the problem, that right braces introduced by the first Replace are escaped again by the second replace. So starting from `{` you get

```
{  -->  {{}  -->  {{{}}

```

which is wrong. To avoid escaping braces introduced precisely as escapes, use a surrogate character for the closing escape brace in the first Replace. E.g. some Chinese character `閉`, assuming that you will never want to send this character.

```
txt = txt.Replace("{", "{{閉");
txt = txt.Replace("}", "{}}");
// After having done the escape, replace the surrogate by the closing brace again.
txt = txt.Replace("閉", "}");

```

If it is not sure whether a single character will never be sent, use a improbable character sequence as surrogate, possibly from different alphabets like `閉©ξ` (Chinese, Latin punctuation, Greek).