Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save the text file as UTF8

Status
Not open for further replies.

spicysudhi

Programmer
Nov 10, 2003
575
FR
Hi

I want to open an already existing text file and save it in the UTF8 format.

Can someone guide me how to do this.

regards,
Sudhi

Yahoo!,MSN,AIM: spicysudhi
 
Short question, short answer:
Open in Word 2k or higher.
"Save as" Encoded text --> Encoding UTF-8

Ah wait: you're in the VB forum, so you probably want code:

Hit F1 and search for "Tristate".
You can open the text file with the help of a FileSystemObject and then write a new one with property "Tristate=mixed"

Hope this helps.

Andy

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
hi

reading the file and writing to a new file with UTF8 format is one option, however it takes more time to do this. I have 130 files like this, each from 50-150MB size.

I tried Stream and it works fine using

Dim stm As ADODB.stream
strPath = "D:\"
Set stm = New ADODB.stream
stm.Open
stm.Charset = "UTF-8"
stm.LoadFromFile strPath & "test.txt"
stm.SaveToFile strPath & "newText.txt", adSaveCreateOverWrite


However the problem with above code is it changes the characters to junk chars when saved in UTF8.

is anyway of doing it in simple way? I have java code to read and write into UTF format, however, its time to process so many files.

regards,
Sudhi
 
Sudhi, wait a minute...
50-150 MegaByte? Text files? Geeeeeeez... [bugeyed]

Have you tried with the FSO as I proposed?

And what do you mean with Java code to read... Are you talking about UTF-8 or about Escape-UTF-8 format?

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
The FSO doesn't create good UTF-8 files (been there, done that).

You need to call the WideCharToMultiByte Win32 API function.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
sorry, i am not VB Guru, just know few commands and managing with that. can you please explain a bit more.

regards,
Sudhi
 
It's complicated. Google is your friend.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
How 'bout a Word 2k macro?

Record one and then put it in a loop like this:
Code:
Sub batchconvert()
Dim thePath As String, i As Integer, theDoc As String

thePath = ActiveDocument.Path
ActiveDocument.Close
With Application.FileSearch
    .LookIn = thePath
    .FileType = msoFileTypeAllFiles
    .FileName = "*.txt"
    .Execute
End With

For i = 1 To Application.FileSearch.FoundFiles.Count
    Documents.Open Application.FileSearch.FoundFiles(i), False
    theDoc = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) - 4) & "_utf8.txt"
    ActiveDocument.SaveEncoding = msoEncodingUTF8
    ActiveDocument.SaveAs theDoc
    ActiveDocument.Close False
Next i

End Sub
Simply open one txt and start the macro. Should do it..
:eek:)

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
hi
many thanks.

I am trying to implement the code in VB. Just for a single file at one time.

i am struglling.

sorry. please help.

regards,
Sudhi
 
>junk chars

Where are you observing these junk chars? I use ADO streams to do this sort of stuff pretty successfully
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top