Important alert: (current site time 7/15/2013 8:01:08 AM EDT)
 

VB icon

Accent Insensitive database querying

Email
Submitted on: 3/23/2003 1:08:33 PM
By: Karabunga 
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB.NET
Views: 16127
(About the author)
 
     Since there is no easy way to have Access or SQL Server support accent insensitive queries, I had to create a function that would fix the problem. With this function, it is possible to turn any SQL query into an accent insensitive query. With a few little modifications, it will also work great with ASP.NET! Converting to C# is a no brainer.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Accent Insensitive database querying
// Description:Since there is no easy way to have Access or SQL Server support accent insensitive queries, I had to create a function that would fix the problem. With this function, it is possible to turn any SQL query into an accent insensitive query. With a few little modifications, it will also work great with ASP.NET! Converting to C# is a no brainer.
// By: Karabunga
//
// Inputs:STRSQL = "SELECT * FROM MyTable WHERE animal LIKE '%" & AccIns("ELEPHANT") & "%'"
This will return any record where animal = Élephant, Elephant, éléphant, eléphant, etc. You Get the picture. Now have fun! :)
//
// Returns:Accent insensitive string to be used in a SQL query
//
// Assumes:The VB6 version of this can be found at http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=9858&lngWId=1
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1080&lngWId=10//for details.//**************************************

Public Shared Function AccIns(ByVal Str As String) As String
Dim sb As New System.Text.StringBuilder()
Dim CurLtr As Char
Dim x As Integer
For x = 1 To Len(Str)
CurLtr = Mid(Str, x, 1)
Select Case CurLtr
Case "e", "é", "è", "ê", "ë", "E", "É", "È", "Ê", "Ë"
sb.Append("[eéèêëEÉÈÊË]")
Case "a", "à", "â", "ä", "A", "À", "Â", "Ä"
sb.Append("[aàâäAÀÂÄ]")
Case "i", "ì", "ï", "î", "I", "Ì", "Ï", "Î"
sb.Append("[iïîìIÏÎÌ]")
Case "o", "ô", "ö", "ò", "O", "Ô", "Ö", "Ò"
sb.Append("[oôöòOÔÖÒ]")
Case "u", "ù", "û", "ü", "U", "Ù", "Û", "Ü"
sb.Append("[uûüùUÛÜÙ]")
Case "c", "ç", "C", "Ç"
sb.Append("[cCçÇ]")
Case Else
sb.Append(CurLtr)
End Select
Next
Return sb.ToString
End Function


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/3/2007 10:09:30 AM

good
(If this comment was disrespectful, please report it.)

 
8/11/2009 5:24:20 AMdangkhoa2601

very good
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.