正则表达式 - 更换与标签的多个空格 [英] Regex - Replacing multiple spaces with tab

查看:213
本文介绍了正则表达式 - 更换与标签的多个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码示例,我想做的是用1 \t替换所有多个空格。

I'm using the code sample below, and what I want to do is replace all multiple spaces with 1 \t.

因此

"I am    having fun             working  on       Regex"

返回

"I am\thaving fun\tworking\ton\tRegex"  

当前代码:

RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);     
tempo = regex.Replace(tempo, @" ");


$ b

谢谢!

Thanks!

推荐答案

只要这样:

resultString = Regex.Replace(subjectString, " {2,}", @"\t");

您忘记了 \t 尝试。

这篇关于正则表达式 - 更换与标签的多个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆