Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.45 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to remove space in the middle using c#
  2. name = name.Replace(" ","");
  3.        
  4. using System;
  5. using System.Text.RegularExpressions;
  6.  
  7. class TestProgram
  8. {
  9.     static string RemoveSpaces(string value)
  10.     {
  11.     return Regex.Replace(value, @"s+", " ");
  12.     }
  13.  
  14.     static void Main()
  15.     {
  16.     string value = "Sunil  Tanaji  Chavan";
  17.     Console.WriteLine(RemoveSpaces(value));
  18.     value = "Sunil  TanajirnChavan";
  19.     Console.WriteLine(RemoveSpaces(value));
  20.     }
  21. }