snipt

Ctrl+h for KB shortcuts

ActionScript 3

truncate all characters after the last '/'

1
2
3
4
var s:String = "test/poo/as.feg";
s = s.substr(0, s.lastIndexOf("/")+1);

trace(s); // test/poo/
https://snippets.siftie.com/embed/9a1e0ecb80235944825e66e5779e3996/
/raw/9a1e0ecb80235944825e66e5779e3996/
9a1e0ecb80235944825e66e5779e3996
as3
ActionScript 3
4
2019-03-05T02:39:40
True
False
False
/api/public/snipt/7385/
truncate-all-characters-after-the-last
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="n">s</span><span class="p">:</span><span class="kt">String</span> <span class="o">=</span> <span class="s2">&quot;test/poo/as.feg&quot;</span><span class="o">;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">s</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="na">substr</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">s</span><span class="o">.</span><span class="na">lastIndexOf</span><span class="o">(</span><span class="s2">&quot;/&quot;</span><span class="o">)+</span><span class="mi">1</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nf">trace</span><span class="o">(</span><span class="n">s</span><span class="o">);</span> <span class="c1">// test/poo/</span> </span></pre></div> </td></tr></table>
as3