Hi everyone, I'm having a problem where in an XML file, if the words in it contain a colon at the end, my translator application does not recognize it and does not find the translated word in a database. The XML file has thousands of words, therefore I cannot simply edit the XML file. In the database for example, there is a word Called Log: There is an equivelent translated for Called Log but not Called Log: <-- with a colon, so the program does not translate the word since it has a colon
foreach
(DataGridViewRow row in dataGridView1.Rows){
var query = transDataContext.Translations.Where(trans => trans.English == row.Cells["Value"].Value.ToString()); if (query.Count() > 0){
Translation translationFound = query.First(); if (!translationsFound.Contains(row.Cells["Value"].Value.ToString())){
if(translationFound.French != string.Empty)translationsFound.Add(row.Cells[
"Value"].Value.ToString(), translationFound.French);}
}
if ((string)translationsFound[row.Cells["Value"].Value] != string.Empty){
row.Cells[
"Translation"].Value = translationsFound[row.Cells["Value"].Value];}
That is part of the code which searches the Database for a equivalent word it works flawlessly for words without colons at the end. How would I construct a check to ignore if there is a colon at the end?
John SimoesPosted Apr 25, 2008, 11:04 AM
I see, this gave me an idea.. the following code segment:
else
if ((query.Count() == 0)&&(row.Cells["Value"].Value.ToString().Contains(":") ==true)){
query = transDataContext.Translations.Where(trans => trans.English == row.Cells[
"Value"].Value.ToString()); MessageBox.Show("String"+row.Cells["Value"].Value.ToString());This code segment identifies the words with a colon at the end, any idea how I would change that query to import them into the cells?
EDIT:
query = transDataContext.Translations.Where(trans => trans.English == row.Cells[
"Value"].Value.ToString().Contains(":"));I'm getting an error that says Operator == cannot be applied to operands of type 'string' and 'bool'
Any ideas how to fix this?
Scott LyslePosted Apr 25, 2008, 10:40 AM
string sTemp = "log:";
int pos = sTemp.Length;
if (sTemp[pos - 1] == ':')
sTemp = sTemp.Remove(pos - 1, 1);
MessageBox.Show(sTemp);