Problems with Buscar with Gambas in SQLite3

Post

Posted
Rating:
#1 (In Topic #1816)
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
Hello everyone
I'm trying to find the descriptions of my data base in Spanish and I have a problem that can't be resolved. The problem is that 'Raúl' has 4 characters and Len or String. Len counts it as 4 but when it passes through the hole in reality it passes 5 characters and two are 'ú' and represents it as a vertical rhombus with a question sign that cannot be asked here. Someone knows what happens. Thank you.

Code (gambas)

Public Function acentoGuion(cadena As String) As String ' cadena = 'Raúl' Dim cadenaNueva As String Dim bBandera As Boolean = False For i As Integer = 0 To String.Len(cadena) - 1 ' Verifica si vocales con acento o no "áéíóúÁÉÍÓÚaeiouAEIOU" If InStr("áéíóúÁÉÍÓÚ", cadena[i]) > 0 Then bBandera = True cadenaNueva &= "_" Else cadenaNueva &= cadena [i]End If Next Return IIf(bBandera, cadenaNueva, cadena) End

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
This may be because you're loading the names from a Windows file. If so, you should convert the string to UTF-8:
See here:
/lang/conv - Gambas Documentation

If you want to remove diacritics, you can use the appropriate gb.util function:
/comp/gb.util/string/removediacritics - Gambas Documentation

However, with the gb.db2 and gb.db2.form components, I have no problems loading diacritics and searching for words with DB.Find.
/comp/gb.db2/db/find - Gambas Documentation

 :goodbye:
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
Thank you very much. The second option you gave me with diacriticism gave me a solution, although I didn't end up using it.

Thank you so much for your help. This is my final solution.

Code (gambas)

Public Function acentoGuion(cadena As String) As String   Dim cadenaNueva As String   Dim bBandera As Boolean = False   For i As Integer = 0 To Len(cadena) - 1     ' Verifica si vocales con acento o no "áéíóúÁÉÍÓÚaeiouAEIOU"     If InStr("áéíóúÁÉÍÓÚ", cadena[i]) > 0 Then       bBandera = True       cadenaNueva &= "_"       i += 1    Else      cadenaNueva &= cadena    [i]End If  Next  Return IIf(bBandera, cadenaNueva, cadena) End

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
I'm glad you solved the problem, but as I said in point 3, databases accept diacritical characters in strings, and there's no need for any strange alchemy.
Gambas provides the DB class for less experienced users (like me  ;)  ), which helps avoid errors.
I'm attaching a small example that should work on all three major databases used in GNU/Linux.
Attachment

FindTestDiacritics-0.0.1.tar.gz

Online now: No Back to the top
1 guest and 0 members have just viewed this.