snipt

Ctrl+h for KB shortcuts

Python

String Methods: Four Methods to the Madness

1
2
3
4
5
6
"""Assign the variable parrot on line 4,
then call len() on parrot on line 5!"""

parrot = "Norwegian Blue"
print len(parrot)
print 
https://snipt.net/embed/9978412c9031b443a74cbb50cdb174bc/
/raw/9978412c9031b443a74cbb50cdb174bc/
9978412c9031b443a74cbb50cdb174bc
python
Python
6
2019-06-25T15:00:21
True
False
False
Apr 20, 2013 at 07:06 PM
/api/public/snipt/59650/
string-methods-four-methods-to-the-madness
<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> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="sd">&quot;&quot;&quot;Assign the variable parrot on line 4,</span> </span><span id="L-2"><a name="L-2"></a><span class="sd">then call len() on parrot on line 5!&quot;&quot;&quot;</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="n">parrot</span> <span class="o">=</span> <span class="s2">&quot;Norwegian Blue&quot;</span> </span><span id="L-5"><a name="L-5"></a><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">parrot</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a><span class="k">print</span> </span></pre></div> </td></tr></table>
programming, python, string

PHP

Camel Case to Underscore

<?php strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $str)); ?>
https://snipt.net/embed/47999ea8a2158e6f1bd5a40d3b15e704/
/raw/47999ea8a2158e6f1bd5a40d3b15e704/
47999ea8a2158e6f1bd5a40d3b15e704
php
PHP
1
2019-06-23T05:18:57
True
False
False
Apr 10, 2013 at 11:44 AM
/api/public/snipt/59073/
camel-case-to-underscore
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nb">strtolower</span><span class="p">(</span><span class="nb">preg_replace</span><span class="p">(</span><span class="s1">&#39;/(?&lt;=[a-z])([A-Z])/&#39;</span><span class="p">,</span> <span class="s1">&#39;_$1&#39;</span><span class="p">,</span> <span class="nv">$str</span><span class="p">));</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"camel case", string, underscore

JavaScript

String long declaration

var longString = "Here's the story, of a man " +
                 "named Brady.";
https://snipt.net/embed/ce93b10a92ec267e987462d7ef201197/
/raw/ce93b10a92ec267e987462d7ef201197/
ce93b10a92ec267e987462d7ef201197
js
JavaScript
2
2019-06-19T08:03:33
True
False
False
Feb 18, 2013 at 09:50 AM
/api/public/snipt/55948/
string-long-declaration
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</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="nx">longString</span> <span class="o">=</span> <span class="s2">&quot;Here&#39;s the story, of a man &quot;</span> <span class="o">+</span> </span><span id="L-2"><a name="L-2"></a> <span class="s2">&quot;named Brady.&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
long, string, syntax