How to build a url path from raw path and arguments? In Drupal 7, from within a module,

My goal is having a menu path (e.g. "/path/to/page/%/%/view/%") and an array of arguments (e.g. array('foo1', 'foo2', 'foo3')), be able to build the resulting path (e.g. "/path/to/page/foo1/foo2/view/foo3").

After looking all over in the Drupal API, I cannot find a function that would do that.

Does such function exist?

EDIT:

The placeholders can be different as well. e.g. "/path/to/page/%user/%blah/view/%". The original raw path is dynamic and is only known during runtime.

I thought that format_string may work for %user and %blah, but what about the % in the end, does format_string work to replace that one too?
I don't think core has a function like that but it's easy enough to write a simple version:

$path = '/path/to/page/%foo/%bar/view/%';
$args = array('foo1', 'foo2', 'foo3');

$wildcards = array();
foreach (explode('/', $path) as $part) {
  if (strpos($part, '%') === 0) {
    $wildcards[] = $part;
  }
}

if (count($args) != count($wildcards)) {
  // Handle it
}

foreach ($args as $key =&gt; $arg) {
  $wildcard = $wildcards[$key];
  $pos = strpos($path, $wildcard);
  if ($pos === FALSE) {
    break;
  }

  $path = substr_replace($path, $arg, $pos, strlen($wildcard));
}
print $path;


Result is: /path/to/page/foo1/foo2/view/foo3