如何查找字符串是否包含除字母数字和特殊字符与其他语言之外的字符混合 [英] How to Find whether the String Contains characters other than Alphanumerics and Special Character with Other Language mixed

查看:181
本文介绍了如何查找字符串是否包含除字母数字和特殊字符与其他语言之外的字符混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,其中包含以下语言的混合:



1)您好,Bing希望您做得好并且您的信息10-09-2015计划for get-together。



在这种情况下,它应该返回true,因为它不包含除字母数字之外的任何其他字符,并且有一些特殊字符,如&。 br />


2)你好,Bingआशा你做得很好和你的信息10-09-2015कीयोजनाबनाईfor Get-together。



但是在这种情况下,它应该返回false,因为它包含除字母数字以外的印地语字符和一些特殊字符,例如 - ,&。



如何在后面的Asp.net代码中验证这一点。

解决方案

一种方法是检查你的字符串是否包含扩展ANSI字符范围之外的字符。



使用Linq

  var  s =   你好,Bingआशा你做得很好&您的信息10-09-2015कीयोजनाबनाईfor Get-together。; 
Console.WriteLine(s.Any(c = > c > 255 ));



相当于

  var  s =  你好,Bingआशा你做得很好&您的信息10-09-2015कीयोजनाबनाईfor Get-together。; 
var any = false ;
foreach var c in s)
{
if (c < = 255 继续;
any = true ;
break ;
}
Console.WriteLine(any);





(您可能希望用常量替换255)


解决方案:您必须编写自己的函数这将检查你的字符串。

- 你必须定义你可以接受的字符列表。

-然后该函数必须检查字符串中的每个字符串你可接受的一组字符/>


根据您所在的国家/地区而定,字母数字字符集不同。

问题

- In法国,éèàçêù可以作为Alpha字符接受

- ascii值低于128的一些字符不是字母数字

= + - * / _(){}&| <>°@ \#,;:?!%

I have a String which Contains mix of language for ex:

1)Hello, Bing Hope you doing well & for Your info 10-09-2015 planned for Get-together.

in this Case it should return me true as it don't contain any other character other than Alphanumeric with some special character like ,&.

2)Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.

But in this Case it should return me false as it contain Hindi Characters other than Alphanumeric with some special character like -,&.

How to Validate this in Asp.net code behind.

解决方案

One way would be to check if your string contains characters outside the range of extended ANSI characters.

Using Linq

var s = "Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.";
Console.WriteLine(s.Any(c => c > 255));


which is the equivalent of

var s = "Hello, Bing आशा you doing well & for Your info 10-09-2015 की योजना बनाई for Get-together.";
var any = false;
foreach (var c in s)
{
    if (c <= 255) continue;
    any = true;
    break;
}
Console.WriteLine(any);



(You might like to replace that 255 with a constant)


Solution: You have to write your own function that will check your string.
-You have to define the list of chars that are acceptable for you.
-then the function have to check every char in your string against your acceptable set of chars.

Depending on which country you are, Alpha-numeric chars are not the same set.
Problems
- In France, éèàçêüù are acceptable as Alpha chars
- some chars with ascii value under 128 are not alpha-numeric
=+-*/_(){}&|"'<>°@\#,?;.:!%


这篇关于如何查找字符串是否包含除字母数字和特殊字符与其他语言之外的字符混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆