Posted on 2004-10-27
Last Modified: 2010-04-15
Hi Experts,

I need to replace all occurances of hyphen and space BETWEEN CHARACTERS (not digits) ONLY within text string with nothing.
example:    ABC- EFH     becomes ABCEFH

Thank you.
Question by:fpoyavo
    LVL 18

    Expert Comment

    you mean something like tihs

    string str = "ABC- EFH- XYZ";
    Console.WriteLine(str.Replace(" ","").Replace ("-",""));
    LVL 7

    Accepted Solution

                     //using System.Text.RegularExpressions;

                      Regex r= new Regex(@"-\s*");
                      MessageBox.Show( r.Replace("abd- asd") );

    when you need

    abc      -     def

    to be adcdef  replace Regex r= new Regex(@"-\s*"); with Regex r= new Regex(@"\s*-\s*");

    now it will do : abc      def

    just giving you options
    LVL 18

    Expert Comment

    fpoyavo .. What was wrong with my answer?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now