<?xml version="1.0" encoding="windows-1252"?>
<node id="169" title="perlfunc:substr" created="1999-08-24 18:41:44" updated="2005-08-15 12:25:17">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
substr - get or alter a portion of a stirng

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
substr 
&lt;FONT SIZE=-1&gt;EXPR,OFFSET,LEN,REPLACEMENT&lt;/FONT&gt;

&lt;P&gt;
substr 
&lt;FONT SIZE=-1&gt;EXPR,OFFSET,LEN&lt;/FONT&gt;

&lt;P&gt;
substr 
&lt;FONT SIZE=-1&gt;EXPR,OFFSET&lt;/FONT&gt;

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
Extracts a substring out of 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; and returns it. First character is at offset &lt;CODE&gt;0&lt;/CODE&gt;, or whatever you've set &lt;CODE&gt;$&amp;#091;&lt;/CODE&gt; to (but don't do that). If 
&lt;FONT SIZE=-1&gt;OFFSET&lt;/FONT&gt; is negative (or more precisely, less than &lt;CODE&gt;$&amp;#091;&lt;/CODE&gt;), starts that far from the end of the string. If 
&lt;FONT SIZE=-1&gt;LEN&lt;/FONT&gt; is omitted, returns everything to the end of the string. If 
&lt;FONT SIZE=-1&gt;LEN&lt;/FONT&gt; is negative, leaves that many characters off the end of the string.

&lt;P&gt;
If you specify a substring that is partly outside the string, the part
within the string is returned. If the substring is totally outside the
string a warning is produced.

&lt;P&gt;
You can use the [perlfunc:substr|substr()] function as an lvalue, in which case 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; must be an lvalue. If you assign something shorter than 
&lt;FONT SIZE=-1&gt;LEN,&lt;/FONT&gt; the string will shrink, and if you assign something longer than 
&lt;FONT SIZE=-1&gt;LEN,&lt;/FONT&gt; the string will grow to accommodate it. To keep the string the same length you may need to pad or chop your value using
 [perlfunc:sprintf|sprintf()].

&lt;P&gt;
An alternative to using [perlfunc:substr|substr()] as an lvalue is to specify the replacement string as the 4th argument. This allows you to replace parts of the 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; and return what was there before in one operation.

&lt;HR&gt;
</field>
</data>
</node>
