|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
regex replace pipe charactersee the 2 NUnit tests below: The first replace works fine and the second Replace does not work. I've tried escaping the pipe character. Can anyone get this to work? Thanks Glenn using System; using NUnit.Framework; using System.Text.RegularExpressions; namespace ScratchPad { [TestFixture] public class ScratchPad { [Test] public void RegexReplace_o() { Regex r = new Regex("bob"); Match m = r.Match("bob"); Assert.AreEqual(true,m.Success); Assert.AreEqual("bb",Regex.Replace("bob","o","")); } [Test] public void RegexReplace_bar() { Regex r = new Regex("b|b"); Match m = r.Match("b|b"); Assert.AreEqual(true,m.Success); //Assert.AreEqual("bb",Regex.Replace("b|b","|","")); } } } > I am having trouble removing a pipe character using Regex.Replace - Regex.Replace("b|b",@"\|","") // works for me> see the 2 NUnit tests below: > > The first replace works fine and the second Replace does not work. > I've tried escaping the pipe character. > > Can anyone get this to work? > Regex.Replace("b|b","|","")); Thanks Jon - its obvious I need the string literal AND the escape - now
you show me. Glenn
Other interesting topics
COM Servers
Break out of Try C# Reflection - Nasty bug?? Communicating between forms... How do I change the radiobutton when listbox selection has changed If statement with multiple condition convert an improper fraction to a mixed number How to select treenode in treeview by name? HELP Problem serializing a structure Retrieving HTTP Response Code |
|||||||||||||||||||||||