Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

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-12-04T00:03:31
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></span><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

C#

C#, Create Delimited string from Array

string.Join(",", TargetList.ToArray());
https://snipt.net/embed/b82e8c432589c5ede6a3e57deba684e9/
https://snipt.net/raw/b82e8c432589c5ede6a3e57deba684e9/
b82e8c432589c5ede6a3e57deba684e9
csharp
C#
1
2016-12-02T16:08:03
True
False
False
/api/public/snipt/53988/
c-create-delimited-string-from-array
<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="kt">string</span><span class="p">.</span><span class="n">Join</span><span class="p">(</span><span class="s">&quot;,&quot;</span><span class="p">,</span> <span class="n">TargetList</span><span class="p">.</span><span class="n">ToArray</span><span class="p">());</span> </span></pre></div> </td></tr></table>
C#, String
Copyrighted, illegal, or inappropriate content? Email [email protected].