From 240f0b329af9f08f08521a8a53494246235549b9 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Thu, 9 Nov 2023 21:31:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=84=E8=AE=BA=E4=B8=AD?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=87=8D=E5=A4=8Dav=E5=8F=B7=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=AF=8C=E6=96=87=E6=9C=AC=E8=A7=A3=E6=9E=90=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=BA=94=E7=94=A8=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/StringExtensions.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/BiliLite.UWP/Extensions/StringExtensions.cs b/src/BiliLite.UWP/Extensions/StringExtensions.cs index 0b3e252e..d811c259 100644 --- a/src/BiliLite.UWP/Extensions/StringExtensions.cs +++ b/src/BiliLite.UWP/Extensions/StringExtensions.cs @@ -86,7 +86,6 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote) { if (txt != null) { - //处理特殊字符 input = input.Replace("&", "&"); input = input.Replace("<", "<"); @@ -358,7 +357,8 @@ private static string HandelVideoID(string input) if (!Regex.IsMatch(input, @"/[aAbBcC][vV]([a-zA-Z0-9]+)")) { //处理AV号 - MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)"); + MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)"); + var offset = 0; foreach (Match item in av) { if (keyword.Contains(item.Groups[0].Value)) @@ -372,11 +372,14 @@ private static string HandelVideoID(string input) string.Format( @" CommandParameter=""{1}"" >{0}", item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value); - input = input.Replace(item.Groups[0].Value, data); + input = input.Remove(item.Index + offset, item.Length); + input = input.Insert(item.Index + offset, data); + offset += data.Length - item.Length; } //处理AV号 MatchCollection bv = Regex.Matches(input, @"[bB][vV]([a-zA-Z0-9]{8,})"); + offset = 0; foreach (Match item in bv) { if (keyword.Contains(item.Groups[0].Value)) @@ -390,12 +393,15 @@ private static string HandelVideoID(string input) string.Format( @" CommandParameter=""{1}"" >{0}", item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value); - input = input.Replace(item.Groups[0].Value, data); + input = input.Remove(item.Index + offset, item.Length); + input = input.Insert(item.Index + offset, data); + offset += data.Length - item.Length; } //处理CV号 MatchCollection cv = Regex.Matches(input, @"[cC][vV](\d+)"); + offset = 0; foreach (Match item in cv) { if (keyword.Contains(item.Groups[0].Value)) @@ -409,7 +415,9 @@ private static string HandelVideoID(string input) string.Format( @" CommandParameter=""{1}"" >{0}", item.Groups[0].Value, "bilibili://article/" + item.Groups[1].Value); - input = input.Replace(item.Groups[0].Value, data); + input = input.Remove(item.Index + offset, item.Length); + input = input.Insert(item.Index + offset, data); + offset += data.Length - item.Length; } }