UCD Search Engine Project summary

本文深入探讨了编程领域的关键技术,包括字符串处理、自动化测试、版本控制等核心技能。从基础的字符串操作如分隔、去标点、去除停用词、双空格去除,到高级应用如链接按钮的使用、域名提取、时间计算,覆盖了从初学者到专业开发者所需的技术栈。同时,文章还展示了如何通过自动化流程提高开发效率,包括使用脚本实现快速构建和测试。内容丰富,旨在帮助读者提升编程能力并掌握实用的开发技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Split the string by BOOLEAN keywords:

Example: split string by "AND"

using System;

namespace stringtest{

class test{

public static void Main() {

        string words = "This is a list of words AND with a bit of punctuation";

        string [] split = words.Split(new Char [] {'A', 'N', 'D'});

        foreach (string s in split) {

            if (s.Trim() != "")
                Console.WriteLine(s);
        }
    }
}

}

************************************************************************************************************************************************************************************

去除一个string中的标点符号

using System.Text.RegularExpressions;
string p = "This is a test string, with lots of: punctuations; in it?!.";
		p = Regex.Replace(p, @"[^\w\s]", "");
		Console.WriteLine(p);
http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.aspx
**************************************************************************************************************************************************************************************

去除stopwords

在搜索引擎中 有很多stopwords会被搜索引擎忽略, 这里是一个去除stopwords的程序

首先把stopwords存储在一个txt文档里面

using System.IO;
using System.Text.RegularExpressions;
string text =
        @"This is a text with lots and lots of stopwords. I am a student, It also talks a bit about load balancing. Load balancing is not a stopword.";

		
		string[] stopwords = File.ReadAllLines(@"stopwords.txt");

		 string regexCode = 
        @"(?<=(\A|\s|\.|,|!|\?))(" + 
        string.Join("|", stopwords) + 
        @")(?=(\s|\z|\.|,|!|\?))";
		
		Regex regex = new Regex(regexCode, RegexOptions.Singleline | RegexOptions.IgnoreCase);
        string cleaned = regex.Replace(text, " ");
        Console.WriteLine("\nAfter remove stopwords:");
        Console.WriteLine(cleaned);
***************************************************************************************************************************************************************************************

去除double space

接着上面的程序,由于去除了stopwords后产生了大量的double space(双倍空白), 所以用下面的程序进行去除

//remove double spaces
		Regex removeDoubleWhiteSpace = 
        new Regex(@"\s{2,}", RegexOptions.Singleline | RegexOptions.IgnoreCase);
        cleaned = removeDoubleWhiteSpace.Replace(cleaned, " ");
        Console.WriteLine("\nAfter remove double white spaces:");
        Console.WriteLine(cleaned);

*************************************************************************************************************************************************************************************

读取文件 的path问题 (如何读取当前目录下的)

string[] stopwords = File.ReadAllLines(HttpContext.Current.Server.MapPath("stopwords.txt")); 
在事件方法中可以用Server.path 但是在code中 需要用 
HttpContext.Current.Server.MapPath
*************************************************************************************************************************************************************************************

How to use LinkButton within Repeater

.aspx
------------------ 
<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("erid") %>'>LinkButton</asp:LinkButton>
    </ItemTemplate>
</asp:Repeater>
 
 
.cs
------------------
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
    if (e.CommandName == "MyUpdate"){
        //e.CommandArgument --> contain the erid value
        //Do something
    }
}

***********************************************************************************************************************************************************************************

How to get the Domain name from the url (handle the String)

string urls = "http://www.dotnetperls.com/groupby";
		
		string FinalUrl;
		if(urls.Contains("www"))
		{
		   FinalUrl = urls.Remove(0,urls.IndexOf(".")+1);
		   FinalUrl = FinalUrl.Substring(FinalUrl.IndexOf(".")+1, FinalUrl.IndexOf("/") - FinalUrl.IndexOf(".")-1);
		}
		else
		{
		   FinalUrl = urls;
		}
		Console.WriteLine(FinalUrl);

Output: com

*************************************************************************************************************************************************************************************

RadionButtonList usage method

http://rhondatipton.net/2006/11/27/radiobuttonlist-control-in-aspnet/

*************************************************************************************************************************************************************************************

计算程序运行时间:

using System.Diagnostics;

private Stopwatch stw = new Stopwatch();

private void Form1_Load(object sender, EventArgs e)
{
stw.Start();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("真的要退出?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
stw.Stop();
MessageBox.Show("程序共运行时间:" + stw.Elapsed.Seconds.ToString() + "." + stw.Elapsed.Milliseconds.ToString() + "秒");
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}

.

****************************************************************************************************************************************************************************************


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值