Skip to content

VDonC#ev

C{}d3

Categories

  • Abstract Data Structures
  • C# Algorithms
  • C# Snippets
  • Combinatorics
  • Java Algorithms
  • Java Snippets
  • Javascript Algorithms
  • PHP

Useful

  • Combinatorial Examples

MINI

Guess the number
Text 2 Array
Notepad

Recent Posts

  • Look And Say Sequence – PHP 7.4
  • Look and Say Sequence in PHP
  • Look and Say Sequence Generator – Javascript (ECMAscript 6)
  • Shortest Path In Graph – Dijkstra’s Algorithm – C# Implementation
  • Minimum Spanning Tree – Kruskal Algorithm – C# Implementation

Replace multiply whitespaces with single space inside text using C#.

using System;
using System.Text.RegularExpressions;

static class ReplaceWhiteSpaces
{
    public static void Main()
    {
        string text = "This is some   text    with        whitespaces in    it   . :     )";
        Console.WriteLine(Regex.Replace(text, @"(\s)\1+", " "));
    }
}
Posted on October 10, 2015December 1, 2019Author vdonchevCategories C# SnippetsTags c#, regex, Regular Expressions, RegularExpressions, replace, whitespaces

Post navigation

Previous Previous post: Easy way to find all palindromes inside string array using C#.
Next Next post: Reverse string with single line of C# code.
Proudly powered by WordPress