Write a Unicode escape character code to a text file

I’ve got C# script that converts a text file with all the game narrative in from the writer and converts it into a string file that can be used in the game. I need to put the Unicode escape characters into the string file by their Unicode codes - so, I need to swap all apostrophes for \u0027 and so on. The text file written out however swaps the Unicode codes back to the character I’m trying to replace - so:

string cleanString = dirtyString.Replace("'","\u0027");

Results in the word “There’s” being written out as “There’s”, rather than “There\u0027s”.

To test I tried putting in another word instead of a code and that worked fine -

 string cleanString = dirtyString.Replace("'","TEST");

Results in “ThereTESTs” so I’m thinking that its the Write process that’s swapping the code back to the character. I’m using SystemIO File.WriteAllText to write the text file.

This is because "'" == "\u0027". If you want “\u0027” to show up in your text file, you have to escape the escape sequence, i.e.

string cleanString = dirtyString.Replace("'","\\u0027");