C#利用Hashtable统计文本关键字出现的次数
作者:hycn 日期:2008-07-31
从网看到一些统计文本关键字次数的例子,今天有一个朋友提醒可以用Hashtable实现。就是把关键字作为Key,而Value值为关键字出现的次数。通过一次循环可以一次构造带有关键词和关键词出现次数的Hashtable。代码实现如下:
class countKeywords
{
public static void Main()
{
Hashtable hashtable = new Hashtable();
string keyWords = @"The elements of the KeyCollection are strongly typed with the type that was specified for hash table keys The elements of the KeyCollection are strongly typed with the type that was specified for hash table keys";
//字符转换为数组
//ArrayList myKeyArray = new ArrayList();
string[] myKeyArray = keyWords.Split(' ');
foreach(string item in myKeyArray)
{
if (hashtable.ContainsKey(item))//
{
hashtable[item] = (int)hashtable[item] + 1;
}
else//不存在此单词则添加,并初始化次为1
{
hashtable.Add(item, 1);
}
}
//输出单词与单词的个数
foreach(DictionaryEntry de in hashtable)
{
Console.WriteLine("关键字:{0},出现的次数为:{1}",de.Key,de.Value);
}
Console.Read();
}
}
如果你有什么好的想法希望留言,大家一起交流。
class countKeywords
{
public static void Main()
{
Hashtable hashtable = new Hashtable();
string keyWords = @"The elements of the KeyCollection are strongly typed with the type that was specified for hash table keys The elements of the KeyCollection are strongly typed with the type that was specified for hash table keys";
//字符转换为数组
//ArrayList myKeyArray = new ArrayList();
string[] myKeyArray = keyWords.Split(' ');
foreach(string item in myKeyArray)
{
if (hashtable.ContainsKey(item))//
{
hashtable[item] = (int)hashtable[item] + 1;
}
else//不存在此单词则添加,并初始化次为1
{
hashtable.Add(item, 1);
}
}
//输出单词与单词的个数
foreach(DictionaryEntry de in hashtable)
{
Console.WriteLine("关键字:{0},出现的次数为:{1}",de.Key,de.Value);
}
Console.Read();
}
}
如果你有什么好的想法希望留言,大家一起交流。
关于.net异常捕获
作者:hycn 日期:2008-07-31
看一个异常的捕获顺序
错误 1 上一个 catch 子句已经捕获了此类型或超类型(“System.Exception”)的所有异常
警告 2 上一个 catch 子句已捕获所有异常。引发的所有非异常均被包装在
catch(Exception e2){}已经捕获了所有的异常,那么下面的IOException将不被执行,出现编译出错。
一般的捕获异常结构为
try
{}
catch(更详细的异常处理1){//处理一}
catch(更详细的异常处理2){//处理二}
...
catch(Exception ex){}
finally{//}
try
{
//you code
}
catch(FileNotFoundException e1)
{
}
catch(Exception e2)
{
}
catch(IOException e3)
{
}
catch
{
}
这个捕获不会通过{
//you code
}
catch(FileNotFoundException e1)
{
}
catch(Exception e2)
{
}
catch(IOException e3)
{
}
catch
{
}
错误 1 上一个 catch 子句已经捕获了此类型或超类型(“System.Exception”)的所有异常
警告 2 上一个 catch 子句已捕获所有异常。引发的所有非异常均被包装在
catch(Exception e2){}已经捕获了所有的异常,那么下面的IOException将不被执行,出现编译出错。
一般的捕获异常结构为
try
{}
catch(更详细的异常处理1){//处理一}
catch(更详细的异常处理2){//处理二}
...
catch(Exception ex){}
finally{//}
查找页面中所有的TextBox并初始为一定的值
作者:hycn 日期:2008-07-31
今天面试里有一个这样的题目,如标题所示。
其实实现很简单,估计考官的主要考点是 is 关键字
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
//页面中控件集
foreach(Control ctl in this.Page.Form.Controls)
{
//估计考官的主要考点是 is 关键字吧
if (ctl is TextBox)
{
TextBox txtBox = (TextBox)ctl;
//或者其它值
txtBox.Text = string.Empty;
}
}
}
查找其它控件并操作也可以按这个思路来。
其实实现很简单,估计考官的主要考点是 is 关键字
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
//页面中控件集
foreach(Control ctl in this.Page.Form.Controls)
{
//估计考官的主要考点是 is 关键字吧
if (ctl is TextBox)
{
TextBox txtBox = (TextBox)ctl;
//或者其它值
txtBox.Text = string.Empty;
}
}
}
查找其它控件并操作也可以按这个思路来。
Tags: 面试
注册人必须保持域名信息正确完整
作者:hycn 日期:2008-07-26
注册人必须保持域名信息正确完整 ?
今天收到一封邮件内容如下:
尊敬的用户:
根据ICANN的规定,注册人必须保持域名信息正确完整
。请您注意及时更新域名的注册信息。
请登录中国域名whois数据查询中心 www.whois-ip.cn 检查您的域名whois信息是否正确
真的以为自己域名信息不正确,不过还是先用Google搜索了一下。
结果,知此为骗子所为。
这个域名为个人所有信息如下
Registry Whois
Domain Search:
Domain Name: whois-ip.cn
ROID: 20080625s10001s77769515-cn
Domain Status: ok
Registrant organization: 贺**
Registrant Name: 贺**
Administrative Email:
Sponsoring Registrar: 厦门华商盛世网络有限公司
Name Server:dns.bizcn.com
Name Server:ns5.cnmsn.net
Name Server:ns6.cnmsn.net
Name Server:dns.cnmsn.net
Registration Date: 2008-06-25 10:39
Expiration Date: 2009-06-25 10:39
Extended Info
IP Address: 222.240.138.38
IP Location: China
Website Status: active
Cache Date: 2008-07-27 02:28:41 MST
Compare Archived Data: 2008-07-18
骗子,让我虚惊一场。
今天收到一封邮件内容如下:
尊敬的用户:
根据ICANN的规定,注册人必须保持域名信息正确完整
。请您注意及时更新域名的注册信息。
请登录中国域名whois数据查询中心 www.whois-ip.cn 检查您的域名whois信息是否正确
真的以为自己域名信息不正确,不过还是先用Google搜索了一下。
结果,知此为骗子所为。
这个域名为个人所有信息如下
Registry Whois
Domain Search:
Domain Name: whois-ip.cn
ROID: 20080625s10001s77769515-cn
Domain Status: ok
Registrant organization: 贺**
Registrant Name: 贺**
Administrative Email:
Sponsoring Registrar: 厦门华商盛世网络有限公司
Name Server:dns.bizcn.com
Name Server:ns5.cnmsn.net
Name Server:ns6.cnmsn.net
Name Server:dns.cnmsn.net
Registration Date: 2008-06-25 10:39
Expiration Date: 2009-06-25 10:39
Extended Info
IP Address: 222.240.138.38
IP Location: China
Website Status: active
Cache Date: 2008-07-27 02:28:41 MST
Compare Archived Data: 2008-07-18
骗子,让我虚惊一场。








