[英]C# Regex to remove single quotes between single quotes
嗨,大家好,我想使用C#正則表達式刪除單引號之間的所有單引號
“這是一個“示例”文字”
請注意,單詞示例位於單引號之間。 我需要我的字符串看起來像:
“這是示例文字”
謝謝!
編輯:
它有一些變化! 現在字符串看起來像:
開始:“這是一個“示例”文字”
請注意,該字符串現在以單詞開頭,后跟: ,然后是第一個單引號'
您不需要使用正則表達式(反正也不適合這種情況)。 嘗試以下方法:
string oldString = "'this is an 'example' text'";
string newString = "'" + oldString.Replace("'","") + "'";
根據您的評論:
string yoursentence = "'this is an 'example' text'";
yoursentence = "'" + yoursentence.Replace("'","") + "'";
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);
}
}
在此處測試此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.