Getting the "String cannot be zero length" error when replacing the French quote character with a regular single quote

C # .NET Framework 1.1: I am trying to replace the French quotation mark with a normal quotation mark. He works on most of our development environment (machine), but when moving to a test environment, the system receives an error string cannot be of zero length .

Here is my code:

 //replace French Quote with normal single Quote fileColumnName = "date d'embauche"; fileColumnName = fileColumnName.Replace("'","'"); 

Is this a problem with character encoding in a test environment?

Update: forgot to mention: this is a component of COM +; Do we have character encoding settings in COM +?

Sorry to be not very clear; here is most of the code: this can be confusing, so to be clear:

fileData is a data table (System.Data.Table) that is populated by connecting OLEDB to a CSV file. Then I get the column names that are compared with the names stored in the database (headerData).

 //#5: Invalid header row check foreach(DataRow hrow in headerData.Rows) { columnNameEnglish = hrow["EnglishDisplayValue"].ToString().ToLower(); //get english column definition columnNameFrench = hrow["FrenchDisplayValue"].ToString().ToLower(); //get french column definition columnIndex = Convert.ToInt32(hrow["DataBaseValue"]); //get corresponding index fileColumnName = fileData.Columns[columnIndex].ColumnName.ToLower(); //replace french Quote with normal Quote fileColumnName = fileColumnName.Replace("'","'"); //check English if(fileColumnName.IndexOf(columnNameEnglish) < 0) { //check French if(fileColumnName.IndexOf(columnNameFrench) < 0) { //invalid row errs.Add("81181"); break; } } } 
+4
source share
2 answers

I found a solution to my problem. I found it sometime, but forgot to update here.

Thanks @Ben. At his suggestion, I used Unicode literals ('\ u2019'), and it was stunned like a charm. I assume this was a CodePage test server problem, but that would not affect Unicode literals.

thanks

0
source

It seems to me that for some reason, your row at the point you are trying to replace has a length of 0. This indicates that the problem is related to the contents of the column that you are retrieving from the database. Thus, I suggest you check your code if the string is empty or empty before trying to replace.

0
source

Source: https://habr.com/ru/post/1490946/


All Articles