We have been struggling with calculating the length of a string which contains Unicode characters
e.g (Word characters such as ’) that get pasted into our systems's
text-area's then get saved. When we need to return that same saved string and we need to calculate our Response
content-length the normal
c# string.Length does not calculate the length correctly since Unicode has more than one character.
We have tried using the
System.Globalization.StringInfo class to read the amount of chars but to no avail as it still comes up short on the correct length of the request. Say for instance the Json response object's last closing curly bracket gets cut off by the browser since the length is too short.
If someone can perhaps shed any light on something that they have used that works it would be greatly appreciated. What we tried so far:
Response.AddHeader("content-length", content.GetType() == typeof(string) ? new System.Globalization.StringInfo(content.ToString()).LengthInTextElements. ToString() : ((byte)content).Length.ToString());