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: 
I would do it using a different variable to hold the entire string:

```
var txt = "asdf{}Asdf";
            var newString = new StringBuilder();
            for (int i = 0; i < txt.Length; i++)
            {
                if (txt[i] == '{')
                    newString.Append("{{}");
                else if(txt[i] == '}')
                    newString.Append("{}}");
                else
                    newString.Append(txt[i]);
            } 
            SendKeys.Send(newString.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).