snipt

Ctrl+h for KB shortcuts

Text only

drawable from string

String mDrawableName = "myimg";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
https://snipt.net/embed/32d4e3d84d3efd75b011cab2678547b9/
https://snipt.net/raw/32d4e3d84d3efd75b011cab2678547b9/
32d4e3d84d3efd75b011cab2678547b9
text
Text only
2
2016-09-24T14:04:16
True
False
False
Aug 02, 2016 at 12:12 PM
/api/public/snipt/147495/
drawable-from-string
<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 id="L-1"><a name="L-1"></a>String mDrawableName = &quot;myimg&quot;; </span><span id="L-2"><a name="L-2"></a>int resID = getResources().getIdentifier(mDrawableName , &quot;drawable&quot;, getPackageName()); </span></pre></div> </td></tr></table>
android, drawable, resource, string

JavaScript

Capitalize String

1
2
3
function capitalize(str) {
	return str.charAt(0).toUpperCase() + str.slice(1);
}
https://snipt.net/embed/4da6e32d983ef5530df98ba966b3cc8c/
https://snipt.net/raw/4da6e32d983ef5530df98ba966b3cc8c/
4da6e32d983ef5530df98ba966b3cc8c
js
JavaScript
3
2016-09-27T06:18:44
True
False
False
Feb 08, 2014 at 02:02 PM
/api/public/snipt/111975/
capitalize-string
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">capitalize</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="nx">str</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">).</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">+</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
capitalize, javascript, js, string

PHP

Sanitize Strings

1
2
3
4
5
6
7
function sanitize($contents) {
	$contents = str_replace("\r\n","\n",$contents); //converts win newlines to nix
	$contents = str_replace("\n\n","\n",$contents); //removes double newlines
	$contents = str_replace("\t","",$contents); //removes tabs

	return $contents;
}
https://snipt.net/embed/5dacba8103cff03eb5136fc4e231861e/
https://snipt.net/raw/5dacba8103cff03eb5136fc4e231861e/
5dacba8103cff03eb5136fc4e231861e
php
PHP
7
2016-09-27T20:09:18
True
False
False
Feb 08, 2014 at 01:53 PM
/api/public/snipt/111971/
sanitize-strings
<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> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">function sanitize($contents) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $contents = str_replace(&quot;\r\n&quot;,&quot;\n&quot;,$contents); //converts win newlines to nix</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> $contents = str_replace(&quot;\n\n&quot;,&quot;\n&quot;,$contents); //removes double newlines</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> $contents = str_replace(&quot;\t&quot;,&quot;&quot;,$contents); //removes tabs</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="x"> return $contents;</span> </span><span id="L-7"><a name="L-7"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
input, php, sanitize, string
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.