snipt

Ctrl+h for KB shortcuts

Java

How to replace “\” with “\\” in java

1
2
3
4
5
6
// Don't use String.replaceAll in this case - that's specified in terms of regular expressions,
// which means you'd need even more escaping. This should be fine:
String escaped = original.replace("\\", "\\\\");

// You could use replaceAll:
String escaped = original.replaceAll("\\\\", "\\\\\\\\");
https://snipt.net/embed/8f55002405ba79b4dc5d4fe8294ba615/
https://snipt.net/raw/8f55002405ba79b4dc5d4fe8294ba615/
8f55002405ba79b4dc5d4fe8294ba615
java
Java
6
2016-09-30T04:33:44
True
False
False
Mar 01, 2016 at 02:23 AM
/api/public/snipt/144510/
how-to-replace-with-in-java
<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 id="L-1"><a name="L-1"></a><span class="c1">// Don&#39;t use String.replaceAll in this case - that&#39;s specified in terms of regular expressions,</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// which means you&#39;d need even more escaping. This should be fine:</span> </span><span id="L-3"><a name="L-3"></a><span class="n">String</span> <span class="n">escaped</span> <span class="o">=</span> <span class="n">original</span><span class="o">.</span><span class="na">replace</span><span class="o">(</span><span class="s">&quot;\\&quot;</span><span class="o">,</span> <span class="s">&quot;\\\\&quot;</span><span class="o">);</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="c1">// You could use replaceAll:</span> </span><span id="L-6"><a name="L-6"></a><span class="n">String</span> <span class="n">escaped</span> <span class="o">=</span> <span class="n">original</span><span class="o">.</span><span class="na">replaceAll</span><span class="o">(</span><span class="s">&quot;\\\\&quot;</span><span class="o">,</span> <span class="s">&quot;\\\\\\\\&quot;</span><span class="o">);</span> </span></pre></div> </td></tr></table>
String, replace

Bash

replace X with Y in all files in a project using sed

sed -i '' -e 's/X/Y/g' $(find . -type f)
https://snipt.net/embed/c195316a2cdd5d8900d146a160c0aba7/
https://snipt.net/raw/c195316a2cdd5d8900d146a160c0aba7/
c195316a2cdd5d8900d146a160c0aba7
bash
Bash
1
2016-09-30T01:21:08
True
False
False
Feb 18, 2014 at 04:52 PM
/api/public/snipt/114908/
replace-x-with-y-in-all-files-in-a-project-using-sed
<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 id="L-1"><a name="L-1"></a>sed -i <span class="s1">&#39;&#39;</span> -e <span class="s1">&#39;s/X/Y/g&#39;</span> <span class="k">$(</span>find . -type f<span class="k">)</span> </span></pre></div> </td></tr></table>
replace, sed

PHP

check keyword in string : strpos()

1
2
3
4
5
6
<?php
// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.
if ( strpos( $all_string , 'keyword' ) !== false ) 
{
	echo 'true ';
}
https://snipt.net/embed/7d2d9604d04d99c86a277981437e7546/
https://snipt.net/raw/7d2d9604d04d99c86a277981437e7546/
7d2d9604d04d99c86a277981437e7546
php
PHP
6
2016-09-29T18:16:28
True
False
True
Aug 27, 2013 at 12:06 AM
/api/public/snipt/77238/
check-keyword-in-string-strpos
<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 id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="p">(</span> <span class="nb">strpos</span><span class="p">(</span> <span class="nv">$all_string</span> <span class="p">,</span> <span class="s1">&#39;keyword&#39;</span> <span class="p">)</span> <span class="o">!==</span> <span class="k">false</span> <span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="s1">&#39;true &#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
change, replace, string
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.