我有一个包含多个连续空格的字符串,我希望用一个替换多个连续的空格 [英] I have a string with multiple consecutive spaces within I wish to substitute multiple consecutive spaces by just one

查看:69
本文介绍了我有一个包含多个连续空格的字符串,我希望用一个替换多个连续的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

在C#

我有一个包含多个连续空格的字符串我希望用一个连续的空格替换一个空格

I have a string with multiple consecutive spaces within I wish to substitute multiple consecutive spaces by just one

example =>

example =>

input => ABC    DE    fg

input => abc   de   fg

output => abc de fg

output => abc de fg

问候

Manoj Gokhale

Manoj Gokhale

推荐答案





您需要进行一个循环,其中两个以上的连续空格消失。

Hi,

You need to make a loop where more than two consecutive spaces disappears.
output = input;
while (output.IndexOf("  ") != -1)
    {
    output = output.Replace("  ", " ");
    }


问候,


这篇关于我有一个包含多个连续空格的字符串,我希望用一个替换多个连续的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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