编程学习网为您整理以下代码实例,主要实现:C#检查字符串是否包含特殊字符,希望可以帮到各位朋友。
using System;
namespace Demo {
class myApplication {
static voID Main(string[] args) {
string str = "Amit$#%";
char[] one = str.tochararray();
char[] two = new char[one.Length];
int c = 0;
for (int i = 0; i < one.Length; i++) {
if (!Char.IsLetterOrDigit(one[i])) {
two[c] = one[i];
c++;
}
}
Array.Resize(ref two, c);
Console.Writeline("Following are the special characters:");
foreach(var items in two) {
Console.Writeline(items);
}
Console.Readline();
}
}
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!