如何将任意字符串转换为符合 CLS 的名称?
有谁知道我可以调用一个算法(或外部库)来将任意字符串(即在我的控制范围之外)转换为符合 CLS 要求?
我正在为 ASP.Net 报表查看器控件生成动态 RDLC(客户端报表定义),并且某些字段名称需要基于用户输入的字符串。
不幸的是,我几乎无法控制客户端输入的字段名称(通过第 3 方 CMS)。但我对创建兼容字符串所需的替换非常灵活。
我现在有一个反应式黑客算法,大致如下:
public static string FormatForDynamicRdlc(this string s)
{
//We need to change this string to be CLS compliant.
return s.Replace(Environment.NewLine, string.Empty)
.Replace("\t", string.Empty)
.Replace(",", string.Empty)
.Replace("-", "_")
.Replace(" ", "_");
}
但我想要更全面的东西。有什么想法吗?
注意:如果有任何帮助,我用来创建动态 RDLC 的算法基于此处找到的 BuildRDLC 方法:http://csharpshooter.blogspot.com/2007/08/revised-dynamic-rdlc- Generation.html
Does anyone know of an algorithm (or external library) that I could call to convert an arbitrary string (i.e. outside my control) to be CLS compliant?
I am generating a dynamic RDLC (Client Report Definition) for an ASP.Net Report Viewer control and some of the field names need to be based on strings entered by the user.
Unfortunately I have little control over the entry of the field names by the client (through a 3rd party CMS). But I am quite flexible around substitutions required to create the compliant string.
I have a reactive hack algorithm for now along the lines of:
public static string FormatForDynamicRdlc(this string s)
{
//We need to change this string to be CLS compliant.
return s.Replace(Environment.NewLine, string.Empty)
.Replace("\t", string.Empty)
.Replace(",", string.Empty)
.Replace("-", "_")
.Replace(" ", "_");
}
But I would love something more comprehensive. Any ideas?
NOTE: If it is of any help, the algorithm I am using to create the dynamic RDLC is based on the BuildRDLC method found here: http://csharpshooter.blogspot.com/2007/08/revised-dynamic-rdlc-generation.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我用来从任意字符串(翻译为 C#)创建 C/C++ 标识符的算法:
如果正则表达式结果的第一个字符不是数字,则不需要前导下划线。
Here's the algorithm I use to create C/C++ identifiers from arbitrary strings (translated to C#):
The leading underscore is unnecessary if the first character of the regex result is not numeric.
我发现以下正则表达式对于分割符合 CLS 的字符串部分和不符合 CLS 的字符串部分很有用。 C# 中的实现如下:
Here is a regex which I found could be useful for splitting CLS-compliant string part and non-CLS-compliant string part. Below implementation in C#: