<p>I am new to golang. sorry if this is a naive question. How can I remove the tailing slash in a path if it exists? Better to use some sdk function.</p>
<hr/>**评论:**<br/><br/>Sythe2o0: <pre><p>I'd look into the <a href="https://golang.org/pkg/path/filepath/" rel="nofollow">filepath</a> package. <a href="https://golang.org/pkg/path/filepath/#Clean" rel="nofollow">Clean</a> will do this: <a href="https://play.golang.org/p/PsXNHAJYWF" rel="nofollow">example</a></p>
<p>edit: if what you're working with isn't a filepath and you don't want as many changes as <code>filepath.Clean</code> imposes, <code>path.Clean</code> also does this, according to its documentation.</p></pre>marksteve4: <pre><p>awesome. Thank you</p></pre>twisted1919: <pre><p>Alternatively, maybe la light weight one <code>strings.TrimRight(path, "/")</code></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传