过滤输入字符串
当我将数据插入表中时,我遇到了过滤字符串的问题。我的意思是像 '
<
等特殊字符,我可以进行简单的替换,但我需要保存原始的字符序列。提前感谢您的帮助。
I faced with problem filtering string when i insert data into my table. I mean special characters like '
<
etc i can do simple replace but i need to save the original sequence of characters. Thanks for help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望通过代码更改字符串,您可以指定要从字符串中删除的字符数组。 String.Join 可以使用 split 方法删除这些字符并将其重新组合在一起
就保存原始序列而言,这是非常模糊的,所以我不确定你的意思,但我想到的是使用数据库并创建第二列,以便您有一列用于输入他们输入的内容,另一列用于固定值。我的脑海中突然浮现出两种方法来控制这个
设计一些功能来剥离字符并保存到
固定值列。这样做的风险是,如果有人决定键入一个您尚未捕获的字符,您不仅会修改该函数,而且还必须针对
计算列规范 - 滑动的任何记录运行此函数
根据要剥离的函数创建表达式
字符并让列控制这个值
这足以消除通过触发器增加的风险。当您修改函数时,因为这是一个计算列,理论上它会更新该值。 (如果我在这里错了,请纠正我,未经测试,只是理论上)
可能不是最有效的方法,但这是我将在当前的工具集中使用的方法。
If you're looking to change the string through code you could specify an array of characters to strip from the string. The String.Join can use the split method to remove those characters and put it back together
In terms of saving the original sequence, this is very vague so I'm not sure what you mean but what pops into my mind is to use the database and create a second column so that you have one for what they entered in, and another for the fixed value. Two ways pop into my head to control this
Database Trigger -
Design some function to strip away characters and save to the
fixed value column. The risk in this is that if someone decides to key a character you have not trapped yet you would not only modify the function but have to run this function against any record that slipped by
Computed Column Specification -
Create an expression based on the function to strip off
characters and let the column control this value
This is sufficient enough to defeat the risk added through the trigger. When you modify the function since this is a computed column it would in theory update the value. (Correct me if I am wrong here, not tested, just in theory)
Probably not the most efficient approaches but this is what I would use with my current toolset.