English 中文(简体)
Regex改为Razor
原标题:Regex Replace function with Razor

我正在寻求以替代功能取代所有特殊性的方法。 我想利用Razak syntax,但这只是这样。

@Product.Name.Regex.Replace(@"[^A-Za-z0-9/s/g]", "_")

不是trick。

我曾试图这样做。

@Regex.Replace(@Product.Name,@"[^A-Za-z0-9/s/g]", "_")

它也失败了。

By now I ve tried a lot of other things and a lot of times I keep getting this error message: "The name Regex does not exist in the current context"

谁能提供帮助?

最佳回答

您需要将<条码>@using System.Text.RegularExpressions添加到你的模板顶。 另外, 这个问题如果你希望在所有模板中提供这一名称空间,将有助于你。

问题回答

正式表达的正确守则是:

@Regex.Replace(@Product.Name,@"[^A-Za-z0-9.,_]", "_")

这将用强调取代所有特殊性质。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签