How do you edit content of a Drupal\Core\Render\Markup instance via a preprocess function in Drupal 8? From doing some experimentation, the only way I've been able to find to get the string property out of an instance of Drupal\Core\Render\Markup is to use the __toString() method:

$variables['fields']['title']-&gt;content-&gt;__toString();


But I'm guessing those initial underscores indicate that this is a private function, not to be used on the outside. Is there some better method to get at the content? My ultimate goal is modifying that content in some way.
You can't edit the content. There is no public method to change it.

Usually you simply override it with a new instance:

$variables['fields']['title'] = Drupal\Core\Render\Markup::create('New content');


The double underscore indicates a magic function, which would be called automatically if you use the object in a string context. This is readonly. 

If you want to add a string to the old markup, that would be an example how the magic function __toString() works:

$variables['fields']['title'] = Drupal\Core\Render\Markup::create($variables['fields']['title'] . '!!!');