How to use sprintf in Url::fromUri? I am trying to convert this from D7 to D8:

l(drupal_strtoupper($field),
sprintf('http://finance.google.com/finance?q=%s',
$exchange . ':' . $field),
array('attributes' =&gt;
array('target' =&gt; '_blank',
       'title' =&gt; (drupal_strlen($title)) ? $title : $field)
)
);


I am doing this and it produced error:

return Link::fromTextAndUrl(Unicode::strtoupper($field), Url::fromUri(sprintf('http://finance.google.com/finance?q=%s'),$exchange . ':' . $field))-&gt;toString();



  InvalidArgumentException: The URI &#039;&#039; is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 281 of core/lib/Drupal/Core/Url.php)
It doesn't really make sense to use sprintf (or any other string formatting/replacement functions) here - the API can already accommodate what you need in a much more structured manner:

$options = ['query' =&gt; ['q' =&gt; $exchange . ':' . $field]];
$url = Url::fromUri('http://finance.google.com/finance', $options);
$link = Link::fromTextAndUrl(Unicode::strtoupper($field), $url);