社区
.NET Framework
帖子详情
关于字符串搜索的问题?
jjyjjyjjy
2006-02-16 11:22:08
我想做一个类似于金山词霸的字符串搜索的界面,但没什么好的字符串搜索算法,实现效果不理想,请问各位老大有什么高见?
...全文
108
3
打赏
收藏
关于字符串搜索的问题?
我想做一个类似于金山词霸的字符串搜索的界面,但没什么好的字符串搜索算法,实现效果不理想,请问各位老大有什么高见?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
杨哥儿
2006-02-17
打赏
举报
回复
有了.
dolfen
2006-02-16
打赏
举报
回复
使用DataTable的Select()方法:
例如(关键代码):
private void searching()
{
DataRow[] drArr=words.Select("word like '" + txtInput.Text + "%'");
if(drArr.Length>0)
{
lstWords.SelectedIndex=Convert.ToInt32(drArr[0]["index"]);
}
}
演示程序全部代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox lstWords;
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.TextBox txtMeans;
DataTable words=new DataTable();
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
//导入词典
words.Columns.Add("index",typeof(long));
words.Columns.Add("word",typeof(string));
words.Columns.Add("means",typeof(string));
//....
//lstWords.DataSource=words.DefaultView;
//(以下是生成测试数据)
lstWords.Items.Clear();
string tmp="abcdefghijklmnopqrstuvwxyz";
string str01="",str02="";
for(int k=0; k<26; k++)
{
str01=tmp.Substring(k%26,1);
for(int j=0; j<26; j++)
{
str02=tmp.Substring(j%26,1);
for(int i=0; i<26; i++)
{
object[] rowVals = new object[3];
rowVals[0]=i+j*26+k*26*26;
rowVals[1]= str01 + str02 + tmp.Substring(i%26,1);
rowVals[2]="【"+rowVals[1].ToString()+"】意思是"+rowVals[0].ToString();
words.Rows.Add(rowVals);
lstWords.Items.Add(rowVals[1].ToString());
}
}
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lstWords = new System.Windows.Forms.ListBox();
this.txtInput = new System.Windows.Forms.TextBox();
this.txtMeans = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lstWords
//
this.lstWords.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lstWords.ItemHeight = 12;
this.lstWords.Location = new System.Drawing.Point(8, 40);
this.lstWords.Name = "lstWords";
this.lstWords.Size = new System.Drawing.Size(200, 316);
this.lstWords.TabIndex = 0;
this.lstWords.SelectedIndexChanged += new System.EventHandler(this.lstWords_SelectedIndexChanged);
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(88, 8);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(384, 21);
this.txtInput.TabIndex = 1;
this.txtInput.Text = "";
this.txtInput.TextChanged += new System.EventHandler(this.txtInput_TextChanged);
//
// txtMeans
//
this.txtMeans.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtMeans.Location = new System.Drawing.Point(216, 40);
this.txtMeans.Multiline = true;
this.txtMeans.Name = "txtMeans";
this.txtMeans.Size = new System.Drawing.Size(256, 320);
this.txtMeans.TabIndex = 2;
this.txtMeans.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 3;
this.label1.Text = "单词:";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(480, 365);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtMeans);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.lstWords);
this.Name = "Form1";
this.Text = "Dolfen词典演示";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void searching()
{
DataRow[] drArr=words.Select("word like '" + txtInput.Text + "%'");
if(drArr.Length>0)
{
lstWords.SelectedIndex=Convert.ToInt32(drArr[0]["index"]);
}
}
private void txtInput_TextChanged(object sender, System.EventArgs e)
{
searching();
}
private void lstWords_SelectedIndexChanged(object sender, System.EventArgs e)
{
txtMeans.Text=words.Rows[lstWords.SelectedIndex]["means"].ToString();
}
}
}
timiil
2006-02-16
打赏
举报
回复
需求能否说得清楚些?
C语言——
字符串
和
字符串
函数
实际上C语言中实际上是没有内置的
字符串
类型的,大部分
字符串
都是以字符型数组和常量
字符串
的形式存在的。在这个例子中,greeting是一个字符数组,自动计算所需的大小以容纳
字符串
及其结尾的空字符\0。这里,buffer...
php判断
字符串
中是否包含指定
字符串
的几种方法
strstr() 函数
搜索
一个
字符串
在另一个
字符串
中的第一次出现。 该函数返回
字符串
的其余部分(从匹配点)。如果未找到所
搜索
的
字符串
,则返回 false。 代码如下: <?php /*如手册上的举例*...
对称
字符串
问题
(详细解答!)
对称
字符串
问题
(详细解答!) 本题原题目来自于蓝桥杯的“密码脱落”
问题
,想见原题请自行
搜索
。 在此概括一下题目大意:给出一个
字符串
,求最多添加多少个字符,能让该
字符串
变为对称
字符串
。 解题主要思路...
C
字符串
与C++
字符串
的对比
C
字符串
与C++
字符串
的对比 C
字符串
在C中,并没有
字符串
这个数据类型,而是使用字符数组来保存
字符串
。C
字符串
实际上就是一个以null('\0')字符结尾的字符数组,null字符表示
字符串
的结束。 C
字符串
定义时可以利用...
linux:如何查找文件中包含制定
字符串
的行?
1、grep “待查找
字符串
” 待查找文件路径 eg:grep "SOFTWARE." /Users/gili/composer.phar 2、cat 待查找文件路径 | grep 待查找
字符串
eg:cat /Users/gili/composer.phar | grep "AS IS" PS:如果执行...
.NET Framework
17,748
社区成员
24,324
社区内容
发帖
与我相关
我的任务
.NET Framework
.NET技术 .NET Framework
复制链接
扫一扫
分享
社区描述
.NET技术 .NET Framework
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章