03-12-24 11:29 AM
Hi,
I have a txt file which contains German texts. When I try to read all texts with Read all lines from text file from Utility-File Management VBO, there is a problem extracting some German letters like ä,ü,ö,ß etc. In the file management VBO, I duplicated the “Read all lines from text file” page and changed the code. But still it can't extract the mentioned German letters. Below code I have written. It would be great if anyone can help me regarding this.
Text = ""
Try
' Read the file using UTF-8 encoding
Text = System.IO.File.ReadAllText(File_Name, System.Text.Encoding.UTF8)
Catch ex As Exception
' Handle exceptions by setting the output to an error message
Text = "Error: " & ex.Message
End Try
Regards,
Ekram
Answered! Go to Answer.
03-12-24 02:06 PM
Are you sure the encoding of the text file you are reading is UTF8? If it is ANSI for example I think that might be the issue.
If you have notepad++ you can open in there and check the lower right hand corner.
vs
Or if you don't have notepad++ you can open in notepad and Save As and see what it defaults to, I don't think that is always a sure fire thing though.
03-12-24 02:21 PM
Hi @mmostaquim ,
Change the encoding to UTF-8 like below in Notepad (Save AS):
If it still doesnot work, change the code with :
Text = System.IO.File.ReadAllText(File_Name, System.Text.Encoding.GetEncoding("ISO-8859-1"))
and save the file encoding to UTF-8. Seems to be working from my end.
you can find the code Identifiers here.
03-12-24 12:13 PM
Hi @mmostaquim ,
I am using the Read All Text From file Action in the File Management - VBO it works well. Attached is the sample text.
Read Text Code:
03-12-24 12:20 PM
I have checked the code of Read All Text From file Action in the File Management - VBO. The code is same like yours. For me, text looks like this "Gesch�ftsbereich"
I cannot find out where is the issue.
03-12-24 01:44 PM
Hi @mmostaquim - we had the same issue but we got this working for norwegian characters åøæ and should work for German as well, try below steps ?
1. Search for "environment variables", and select Edit system environment variables option
2. Go to advanced tab - Environment variables
3. Go down to the System variables, and press new
4. In the pop up box, set the Variable name to "NLS_LANG" and the value to "AMERICAN_AMERICA.WE8ISO8859P1" (Without the ")
5. Press OK \ Apply
6. Restart and try again
03-12-24 02:06 PM
Are you sure the encoding of the text file you are reading is UTF8? If it is ANSI for example I think that might be the issue.
If you have notepad++ you can open in there and check the lower right hand corner.
vs
Or if you don't have notepad++ you can open in notepad and Save As and see what it defaults to, I don't think that is always a sure fire thing though.
03-12-24 02:15 PM
Unfornately, i do not have notepad++. I have tried with notepad and save as. I think it is defined as ANSI.
03-12-24 02:21 PM
Hi @mmostaquim ,
Change the encoding to UTF-8 like below in Notepad (Save AS):
If it still doesnot work, change the code with :
Text = System.IO.File.ReadAllText(File_Name, System.Text.Encoding.GetEncoding("ISO-8859-1"))
and save the file encoding to UTF-8. Seems to be working from my end.
you can find the code Identifiers here.
04-12-24 07:26 AM
hi @Chakkravarthi_PR, thanks for the solution. After saving the txt file with UTF format, Read All Text From file Action in the File Management - VBO can read german letters.