<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>ema_hiro</author_name>
  <author_url>https://blog.hatena.ne.jp/ema_hiro/</author_url>
  <blog_title>emahiro/b.log</blog_title>
  <blog_url>https://ema-hiro.hatenablog.com/</blog_url>
  <categories>
    <anon>Go</anon>
  </categories>
  <description>Overview Go で文字列の中で特定の文字を別の文字に置換したいケース、例えば改行コードやタブが混じっている文字列の中で特殊文字だけをエスケープしたいケースなどで strings.Replace を多用するのではなく、一括で置換する実装について記載します。 strings.NewReplacer を使う https://pkg.go.dev/strings#example-NewReplacer を使います。 使い方 以下のような実装でタブと改行コードを一括でエスケープ可能です。 strings.NewReplacer(&quot;\t&quot;, &quot;\\t&quot;, &quot;\n&quot;, &quot;\\n&quot;, &quot;\r&quot;, &quot;\…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fema-hiro.hatenablog.com%2Fentry%2F2024%2F09%2F17%2F222830&quot; title=&quot;Go で複数の文字を一括で別の文字に置換する - emahiro/b.log&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2024-09-17 22:28:30</published>
  <title>Go で複数の文字を一括で別の文字に置換する</title>
  <type>rich</type>
  <url>https://ema-hiro.hatenablog.com/entry/2024/09/17/222830</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
