近音搜索,比较输入Z就可以搜索到拼音Z开头的汉字,搜索"浙江",只要输入"ZJ"就可以了...






相关算法如下:
有兴趣可以测试一下,希望能给你带来帮助
None.gif   using  System;
None.gif 
using  System.Text;
None.gif 
using  System.IO;
ExpandedBlockStart.gifContractedBlock.gif 
namespace  ts dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
class testdot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif 
private static string[] startChars = dot.gif{"""""","","","","","","","","","","","","","",
ExpandedSubBlockEnd.gif              
"","""","","","","","","",""}
;
ExpandedSubBlockStart.gifContractedSubBlock.gif   
private static string[] endChars = dot.gif{"""""","","","","","","","","","","","","","",
ExpandedSubBlockEnd.gif               
"","""","","","","","","",""}
;
InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
/**//// <summary>
InBlock.gif   
/// 根据字符和对应的中文字符,转成SQL查询条件
InBlock.gif   
/// </summary>
InBlock.gif   
/// <param name="cChar">要转化的字符,[A-Z]</param>
InBlock.gif   
/// <param name="strFieldName">条件左值</param>
InBlock.gif   
/// <returns>SQL条件</returns>
ExpandedSubBlockEnd.gif   
/// <remarks> Sxf 2001-1-4 ***** JY 2002-1-4 </remarks>

InBlock.gif   public static string GetCharCondition(char cChar, string strFieldName)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
string strWord;
InBlock.gif    
int Index = (int)(char.ToUpper(cChar)) - (int)'A';
InBlock.gif    
if (Index >= 0 && Index < 26)
InBlock.gif     strWord 
= startChars[Index];
InBlock.gif    
else
InBlock.gif     strWord 
= startChars[0];
InBlock.gif    
//            return string.Format("(({0}>='{1}' AND {0}<'[') OR ({0} >= '{3}' AND {0} < '{{') OR {0}>='{2}')", 
InBlock.gif    
//                strFieldName, char.ToUpper(cChar), strWord, char.ToLower(cChar));
InBlock.gif
    return string.Format("(({0} >= '{3}' AND {0} <= 'zzzzzzzz') OR {0}>='{2}')"
InBlock.gif     strFieldName, 
char.ToUpper(cChar), strWord, char.ToLower(cChar));
ExpandedSubBlockEnd.gif   }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif         
/**//// <summary>
InBlock.gif         
/// 将指定字段值的每个字符分割,这样可以生成同音查询的SQL
InBlock.gif         
/// </summary>
InBlock.gif         
/// <param name="fieldName">字段名</param>
InBlock.gif         
/// <param name="fieldValue">字段值</param>
ExpandedSubBlockEnd.gif         
/// <returns>生成的可以进行同音查询的SQL</returns>

InBlock.gif   public static string GetCharFullCondition(string fieldName, string fieldValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    StringBuilder sql 
= new StringBuilder(1024);
InBlock.gif    
int i = 1;
InBlock.gif    
foreach (char c in fieldValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if (i > 1)
InBlock.gif      sql.Append(
" AND ");
InBlock.gif     
int index = (int)(char.ToUpper(c)) - (int)'A';
InBlock.gif     
string startWord, endWord;
InBlock.gif     
if (index >= 0 && index < 26)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      startWord 
= startChars[index];
InBlock.gif      endWord 
= endChars[index];
ExpandedSubBlockEnd.gif     }

InBlock.gif     
else
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      startWord 
= startChars[0];
InBlock.gif      endWord 
= endChars[0];
ExpandedSubBlockEnd.gif     }

InBlock.gif     
string subStr = String.Format("SUBSTRING({0}, {1}, {2})", fieldName, i, 1);
InBlock.gif     sql.AppendFormat(
"({0} BETWEEN '{1}' AND '{2}')", subStr, startWord, endWord);
InBlock.gif     
++i;
ExpandedSubBlockEnd.gif    }

InBlock.gif 
InBlock.gif    
return sql.ToString();
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值