<p>So i have a string and its a lot like this;</p>
<p>bla abdkjdka|dfhskfjh|su98ujsdf|sljdfksjf|...</p>
<p>I am writing that information to a file use bufio.NewWriter and i want each part on a new line in the file like so....</p>
<p>bla abdkjdka</p>
<p>dfhskfjh</p>
<p>su98ujsdf</p>
<p>sljdfksjf</p>
<hr/>**评论:**<br/><br/>madman2233: <pre><pre><code>\n
</code></pre>
<p>or on windows systems:</p>
<pre><code>\r\n
</code></pre>
<p>you could do</p>
<pre><code>output := strings.Replace(input, "|", "\n", -1)
</code></pre>
<p>windows: </p>
<pre><code>output := strings.Replace(input, "|", "\r\n", -1)
</code></pre></pre>Morgahl: <pre><p>Maybe a bit of an over engineered example but this would allow you to wrap your os.File(or any other io.Writer) with an io.Writer to allow streaming data while replacing '|' with either '\n' or '\r\n'</p>
<p><a href="https://play.golang.org/p/zOriezNUn7" rel="nofollow">https://play.golang.org/p/zOriezNUn7</a></p></pre>earthboundkid: <pre><p><code>fmt.Fprintln(buf, "my line")</code></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传