You are not logged in.

1

Saturday, February 19th 2011, 3:38pm

Accented Character

Hello everyone.

I migrated my files (.txt) from Windows (ISO-8859) to Linux (UTF-8).

Replace command is not recognizing the accented character.

Source code

1
2
3
4
5
6
7
8
QFile file(fileName);
file.open(QIODevice::ReadOnly|QIODevice::Text);
QTextStream in(&file);
QString str = in.readAll().trimmed();
file.close();

const char tA[4] = {'á','â','ã','à'};
for (int j = 0; j < (int)sizeof(tA); j++) str.replace(tA[j],"a");


Does anyone know what command I have to use or add?

Thanks

Junior

Professional

  • "Junior" is male

Posts: 1,613

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Monday, February 21st 2011, 3:36pm

You might be able to use the QTextStream for this, check on QTextStream::setCodec( .. );

3

Thursday, February 24th 2011, 10:25pm

Thanks for the help. I solved using the ASCII code.

Source code

1
2
3
4
5
6
7
//UTF-8 ASCII Table
const char tA[4] = {225,226,227,228}; //á,â,ã,à
const char tE[2] = {233,234}; //é,ê
const char tI[1] = {237}; //í
const char tO[3] = {243,244,245}; //ó,ô,õ
const char tU[2] = {250,252}; //ú,ü
const char tC[1] = {231}; //ç


Source code

1
2
3
4
5
6
for (unsigned int j = 0; j < sizeof(tA); j++) str.replace(tA[j],"a");
for (unsigned int j = 0; j < sizeof(tE); j++) str.replace(tE[j],"e");
for (unsigned int j = 0; j < sizeof(tI); j++) str.replace(tI[j],"i");
for (unsigned int j = 0; j < sizeof(tO); j++) str.replace(tO[j],"o");
for (unsigned int j = 0; j < sizeof(tU); j++) str.replace(tU[j],"u");
for (unsigned int j = 0; j < sizeof(tC); j++) str.replace(tC[j],"c");