删除两个或Word空间之间有更多的空 [英] remove two or more empty between space in word

查看:176
本文介绍了删除两个或Word空间之间有更多的空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与破折号之间的字替换 C#任何空间。但我的问题是,当我想删除这样的样本字符串空间:

I want to replace any space between in word in with dash in C#. But my problem is when I want remove space in sample string like this:

"a  b"

"a    b"

当我尝试,我得到这个结果:

When I try this, I get this result:

A - BA --- B

我怎样才能把一条虚线的字之间的间距的计数?

How can I put one dash for any count of space between the word?

这样的:

一B

A-B

推荐答案

您可以使用如下

string xyz = "1   2   3   4   5";
xyz = string.Join( "-", xyz.Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries ));

参考


  1. How做我代替多个空格,在C#一个空间?

  2. How与一个空白
  3. 替换多个空格
  1. How do I replace multiple spaces with a single space in C#?
  2. How to replace multiple white spaces with one white space

这篇关于删除两个或Word空间之间有更多的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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