Android Question problem with replace function

DALB

Active Member
Licensed User
Hello,

Here is a syntax which doesn't work:
B4X:
mot=mot.replace("é","e")
In my language, for instance, the letter "é" can't be changed to "e" with the 'Replace' function.

B4A returns this:
android.database.sqlite.SQLiteException: near "diff�rents": syntax error (code 1): , while compiling: INSERT INTO bnotes VALUES (1, science, les diff�rents domaines de la science, analyse, 15/05/2021, 20210515, 0)

You can see the sign in the word different.

Is there a way to make it possible ?
If someone comes here, thanks to him !
Every idea is welcome.
 

DALB

Active Member
Licensed User
replace(chr(233),"e") doesn't work too !
 
Upvote 0

DALB

Active Member
Licensed User
otherwise...
How to detect an unknown character to convert it into a known sign ? Maybe this way could help.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am afraid that there is an encoding problem somewhere.
This code works:
B4X:
    Private mot As String
    mot = "séf"
    Log(mot)
    mot = mot.Replace("é", "e")
    Log(mot)
You need to give us more information.
Where does 'diff�rents' come from?
 
Upvote 0

DALB

Active Member
Licensed User
One not too bad solution waiting a better one....
the unknown character has an ASCII number which is 65533.
Here ASC('the unkwon character') = 65533
I replace it by a special one like '§', and SQLITE accept it for saving my datas.
 
Upvote 0

DALB

Active Member
Licensed User
B4X:
Where does 'diff�rents' come from?
it's a term coming from a list of words written in french.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
"différents" comes from a list which was generated
in an 1-byte character set (eg, iso-8859-1, windows 1252,
etc). you need to convert it to utf-8.

when you take something like "différents" from such a
list and use a multi-byte character set (eg, utf-8),
you get "diff�rents", the "é" character not being the
same in both character sets.

replace() and sqlite's insert work just fine if your list
is in utf-8.
 
Last edited:
Upvote 0

DALB

Active Member
Licensed User
Klaus,

the list is entered manually. I have built a little app to note little things about different subjects.


drgottjr

Thanks I'll try soon and come back to say what about !
 
Upvote 0

DALB

Active Member
Licensed User
Yes, through windows, because a text file can be imported. So I'll try drgottjr method soon.

The app can work like this:

A) the text is entered directly in the Edittext zones....no problem

B) the texts are in a text file filled with a text software like Word, Text, etc... and imported by email or sms.
 
Upvote 0

DALB

Active Member
Licensed User
With UTF-8, it doesn't work.
But I found that there is a 'UTF-8 with nomenclature' (I don't exactly know the difference, I'll see this after), and it works well.
So my question in this case is:
What is the name of the code UTF-8 with nomenclature in this piece of code ?

B4X:
Sub Utf2Bytes( s As String ) As Byte()
    Return s.getbytes("UTF-8")
End Sub

Sub Bytes2Utf( b() As Byte ) As String
    Return BytesToString( b, 0, b.Length, "UTF-8" )
End Sub

coming from
UTF-8 use

What do I have to write in the quotes "UTF-8 something", because the files can arrive from many sources ?
 
Upvote 0

DALB

Active Member
Licensed User
O kay thanks for this. I'll change some part of my code to easily import the different files;
 
Upvote 0
Top