在许多相同的标记上应用Regex.Replace

时间:2018-01-13 16:56:35

标签: c# regex string

这是我的代码:

rotate

我想摆脱using System; using System.Text; using System.IO; using System.Text.RegularExpressions; namespace ConsoleApplication33 { class Program { static void Main(string[] args) { string line = "\"aaaaa\"" + "aaaaa" + "\"aaaaa\"" + "aaaaa" + "\"aaaaa\""; line = Regex.Replace(line, "\".+\"", ""); Console.WriteLine(line); Console.Read(); } } } 并保留"aaaaa"

所以使用这个字符串,我应该得到aaaaa

但是代码我什么都没得到。

那么我该如何解决这个问题呢?

2 个答案:

答案 0 :(得分:3)

我认为你应该.+?非贪婪// the pixel array of uint 32-bit colors var pixelArray = new uint[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00 }; // create an empty bitmap bitmap = new SKBitmap(); // pin the managed array so that the GC doesn't move it var gcHandle = GCHandle.Alloc(pixelArray, GCHandleType.Pinned); // install the pixels with the color type of the pixel data var info = new SKImageInfo(2, 2, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul); bitmap.InstallPixels(info, gcHandle.AddrOfPinnedObject(), info.RowBytes, null, delegate { gcHandle.Free(); }, null);

Output c#

答案 1 :(得分:0)

我也尝试过,你应该替换.+ to .+?

Sample Code