1 of 4

Extracting text from cells, preserving non-ASCII characters

Consider the following setup, based on this answer by WReach:

eval = (ToString[#] &)

 Cell[TextData["őúű"], "Program", 
  Evaluatable -> True,       
  CellGroupingRules -> "InputGrouping",
  CellEvaluationFunction -> eval]]

This will create a cell that, when evaluated, will simply output its own contents, converted to a string. My goal is to preserve non-ASCII characters during this conversion.

Notice that with the example contents I included, I get this string as output


This is not the same as the input, "őúű". The difference is not just in display, it's actually a different string as you can verify using StringLength or exporting the string to a file. What I need to get is:


i.e. a string of length 3.

How can I get this?