Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Other formats

Notices

Reply
 
Thread Tools Search this Thread
Old 12-05-2010, 08:45 PM   #1
bizzybody
Addict
bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.
 
Posts: 288
Karma: 7742186
Join Date: Apr 2007
Location: Idaho, USA
Device: Various PalmOS PDAs, Android Phones, Sharper Image Literati
Text File String Replacer

The attached program and Visual Studio 2010 source code is by Richard Twyning in the UK.

What it does is mass replacements of strings of text with other strings of text contained in one or more text or HTML files, or any file that's plain text.

The Book1.txt file is a sample of how the replacementfile.txt is organized.

However, that file is too long for the program. On exit, the program re-sorts replacementfile.txt by the character values of the odd numbered lines, which are the to-be-replaced strings in the source file(s). If there's too many lines it truncates the file.

Another issue is it doesn't work properly with Windows 1252 (or Extended ASCII) characters from 128 on up. It replaces them in replacementfile.txt with some non-printable character, but only when the replacementfile.txt file is over some unknown length. I tried removing all the codes for the ten digits and the regular upper and lowercase letters but it still fouled up characters higher than number 128, but didn't truncate the file.

As it is, as long as the replacement file is kept short enough, it works.

If I can get Visual Studio 2010 I'll take a stab at curing those bugs. I posted the program and source here in case anyone else wants to give it a go or use it as an example or part of some other project. Richard based this partly on other open source code.

The goal for my use is to have a replacementfile.txt that has every possibility of UTF-8 code in it, with and without leading zeros and all cases of where more than one code corresponds to the same Extended ASCII or Windows 1252 character. Then it'll be a much less time consuming job to convert UTF-8 encoded files for further conversions for any platform that does not support Unicode. (In my case that means Palm OS!)

With the replacementfile.txt bugs squashed, this program could be very useful for many other purposes. It does work fine in a limited fashion now, good enough for processing HTML files to run through Mobipocket Creator, which so far is the only Mobi converter I've found that properly groks Windows 1252 encoding using extended characters and will not foul it up in the conversion by assuming the output ought to be Unicode.

One idea I had was using it for simple OTP cipher encryption. Pass a source document through this several times using a series of replacement files, send it to another party, who uses another set of replacement files in opposite order to decode. Like with all OTP systems, getting the decoding code(s) to the destination party securely is the problem.

Another use could be doing replacements in source code files, especially if you need to make huge numbers of changes. Find and replace in most text editors can do one change at a time on every instance of that single change. This program can do many different changes on every instance of all the changes in a single pass.

Anyway, I posted it here so people can make of it what they will and perhaps expand it or find it useful in some way.
Attached Files
File Type: txt Book1.txt (2.4 KB, 399 views)
File Type: rar TextFileStringReplacer-source.rar (118.6 KB, 438 views)
File Type: rar Text file string replacer2.rar (77.2 KB, 460 views)

Last edited by bizzybody; 12-05-2010 at 08:48 PM.
bizzybody is offline   Reply With Quote
Old 12-08-2010, 06:49 AM   #2
mrmikel
Color me gone
mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.
 
Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
You can get 150 days worth of Visual Studio 2010 here:

http://www.microsoft.com/visualstudio/en-us/download
mrmikel is offline   Reply With Quote
Advert
Old 12-20-2010, 05:20 AM   #3
bizzybody
Addict
bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.bizzybody ought to be getting tired of karma fortunes by now.
 
Posts: 288
Karma: 7742186
Join Date: Apr 2007
Location: Idaho, USA
Device: Various PalmOS PDAs, Android Phones, Sharper Image Literati
The code is written in C# so the full Visual Studio isn't required to do stuff with this source code.
bizzybody is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with reflow text file siulayhumga Workshop 9 07-31-2010 06:36 PM
text file and table of content skao Calibre 1 04-09-2010 12:15 PM
text file formatting hobbyman Calibre 5 10-05-2008 05:18 PM
Text File with web links? schulzmc Amazon Kindle 3 05-23-2008 03:06 PM
text file tricks kenbaldwin Sony Reader 0 07-27-2007 10:07 AM


All times are GMT -4. The time now is 10:18 AM.


MobileRead.com is a privately owned, operated and funded community.