<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Subst$
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../lang+en">Up</a>&nbsp;
<a href="sub+en">Previous</a>&nbsp;
<a href="super+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Subst$
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><u>Result</u> <b>= Subst$ (</b> <u>Pattern</u> <b>,</b> <u>ReplaceString</u> [ <b>,</b> <u>ReplaceString</u> ] <b>)</b>
<u>Result</u> <b>= Subst (</b> <u>Pattern</u> <b>,</b> <u>ReplaceString</u> [ <b>,</b> <u>ReplaceString</u> ] <b>)</b></pre><p>

Replaces substrings <tt>&amp;1</tt>, <tt>&amp;2</tt>, etc. in a pattern with the first, second, and subsequent <u>ReplaceString</u> argument respectively, and returns the result.
<p>
If <u>Pattern</u> is null, then a null string is returned.
<p>
For C developers, this is not unlike a simplified <tt>sprintf</tt>.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PRINT Subst(&quot;Gambas is a cool &1&quot;, &quot;BASIC&quot;)
<hr>Gambas is a cool BASIC</pre>
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/warning.png" align="center"></td><td valign="top">
This function is very useful when you must concatenate strings that must be translated.
Do not use the <tt>&amp;</tt> operator, as the order of concatenation might change with the language.
<p>
For example:
<p>
<div class="box">
<tt><a href="print+en">PRINT</a> Subst((&quot;Today, we are &1 &2&quot;), <a href="format+en">Format$</a>(Now, &quot;mmm&quot;), <a href="format+en">Format$</a>(Now, &quot;d&quot;))</tt>
</div>
<p>
will be translated in french this way:
<p>
<div class="box">
<tt><a href="print+en">PRINT</a> Subst((&quot;Aujourd'hui, nous sommes le &2 &1&quot;), <a href="format+en">Format$</a>(Now, &quot;mmm&quot;), <a href="format+en">Format$</a>(Now, &quot;d&quot;))</tt>
</div>
</td></tr></table></div>
<p>
<hr><b>See also</b><br>
<a href="../cat/string+en">String Functions</a>&nbsp;

</div>
</body>
</html>

