如何检测字符串是否包含特殊字符? [英] How to detect if a string contains special characters?
本文介绍了如何检测字符串是否包含特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测字符串是否包含特殊字符,如#、$、^、&、*、@、!SQL Server 2005 中的等(非字母数字字符)?
How to detect if a string contains special characters like #,$,^,&,*,@,! etc (non-alphanumeric characters) in SQL server 2005?
推荐答案
假设 SQL Server:
Assuming SQL Server:
例如如果您将特殊字符归类为非字母数字:
e.g. if you class special characters as anything NOT alphanumeric:
DECLARE @MyString VARCHAR(100)
SET @MyString = 'adgkjb$'
IF (@MyString LIKE '%[^a-zA-Z0-9]%')
PRINT 'Contains "special" characters'
ELSE
PRINT 'Does not contain "special" characters'
只需在方括号内添加您不属于特殊类别的其他字符
Just add to other characters you don't class as special, inside the square brackets
这篇关于如何检测字符串是否包含特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文