I have a string: <p><img title="\pi a{^{2}}" src="http://latex.codecogs.com/gif.latex?\pi&space;a{^{2}}" /></p>
I want to replace it using base64 string.
Code:
string soalP = file.Path;
string decodeFile = Uri.UnescapeDataString(file.DisplayName);
byte[] imageArray = System.IO.File.ReadAllBytes(soalP);
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
soal = Regex.Replace(soal, "\"http://latex.codecogs.com/gif.latex?" + "\\" + decodeFile + "\"", "data:image/jpeg;base64," + base64ImageRepresentation);
I have a error message:
parsing '"http://latex.codecogs.com/gif.latex?\pi&space;a{^{2}}"' - Malformed \p{X} character escape.
How to handle it?
Note:
I downloaded the picture first and saved it in the local folder.
The file name is encoded file name
Since you are using regular expressions, in the Regex.Replace() method, the second argument is treated as a regular expression for parsing. When there are special characters in the string, it may be mistaken as the symbol resolution of the regular expression, which leads to failure. If you are still confused about the backslash, you can use the string.Replace() method for character substitution.
soal = soal.Replace("\"http://latex.codecogs.com/gif.latex?" + "\\" + decodeFile + "\"", "data:image/jpeg;base64," + base64ImageRepresentation);