Reputation: 530
Hi guys i want to remove all single quotes between single quotes using C# regex, example
'this is an 'example' text'
Note that word example is between single quotes. I need that my string looks like:
'this is an example text'
Thanks!
EDIT:
It have some changes! now the string look like:
begin:'this is an 'example' text'
Note that the string now start with a word followed by : and then the first single quote '
Upvotes: 1
Views: 5512
Reputation: 43673
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string str = "begin:'this is an 'example' text'";
str = Regex.Replace(str, "(?<=')(.*?)'(?=.*')", "$1");
Console.WriteLine(str);
}
}
Test this code here.
Upvotes: 2
Reputation: 3919
string yoursentence = "'this is an 'example' text'";
yoursentence = "'" + yoursentence.Replace("'","") + "'";
Upvotes: 2
Reputation: 1533
You don't need to use regex (and it's not very well suited to this situation anyway). Try this instead:
string oldString = "'this is an 'example' text'";
string newString = "'" + oldString.Replace("'","") + "'";
Upvotes: 3
Reputation: 10579
Based on your comments:
Upvotes: 2