</head> <body> <h1>SubStr() <span class="ver">[v1.0.46+]</span></h1> <p>Retrieves one or more characters from the specified position in a string.</p> <pre class="Syntax">NewStr := <span class="func">SubStr</span>(String, StartingPos <span class="optional">, Length</span>)</pre> <h2 id="Parameters">Parâmetros</h2> <dl> <dt>String</dt> <dd><p>The string whose content is copied.</p></dd> <dt>StartingPos</dt> <dd><p>Specify 1 to start at the first character, 2 to start at the second, and so on (if <em>StartingPos</em> is beyond <em>String</em>'s length, an empty string is returned). If <em>StartingPos</em> is less than 1, it is considered to be an offset from the end of the string. For example, 0 extracts the last character and -1 extracts the two last characters (but if <em>StartingPos</em> tries to go beyond the left end of the string, the extraction starts at the first character).</p></dd> <dt>Length</dt> <dd><p>If this parameter is omitted, it defaults to "all characters". Otherwise, specify the maximum number of characters to retrieve (fewer than the maximum are retrieved whenever the remaining part of the string is too short). You can also specify a negative <em>Length</em> to omit that many characters from the end of the returned string (an empty string is returned if all or too many characters are omitted).</p></dd> </dl> <h2 id="Return_Value">Return Value</h2> <p>This function returns the requested substring of <em>String</em>.</p> <h2 id="Remarks">Remarks</h2> <p>Functionally, the <strong>SubStr</strong> function is almost the same as the <a href="StringMid.htm">StringMid</a> command. However, it's recommended to use SubStr, because it is more flexible and future-proofed than StringMid.</p> <h2 id="Related">Tópicos relacionados</h2> <p><a href="RegExMatch.htm">RegExMatch()</a>, <a href="StringMid.htm">StringMid</a>, <a href="StringLeft.htm">StringLeft/Right</a>, <a href="StringTrimLeft.htm">StringTrimLeft/Right</a></p> <h2 id="Examples">Exemplos</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> Retrieves a substring with a length of 3 characters at position 4.</p> <pre>MsgBox % SubStr("123abc789", 4, 3) <em>; Returns abc</em></pre> </div> <div class="ex" id="ExStartEnd"> <p><a class="ex_number" href="#ExStartEnd"></a> Retrieves a substring from the beginning and end of a string.</p> <pre>String := "The Quick Brown Fox Jumps Over the Lazy Dog" MsgBox % SubStr(String, 1, 19) <em>; Returns "The Quick Brown Fox"</em> MsgBox % SubStr(String, -7) <em>; Returns "Lazy Dog"</em> </pre> </div> </body> </html>