Re: Splitting a large string variable into lines <= 70 chars

Tech-Archive recommends: Speed Up your PC by fixing your registry



I kinda agree with you that perhaps the string search methods and functions like InStrRev and LastIndexOf will not be the fastest way.

Also perhaps not the fastest way but I'm impressed with the, new to me at least, split command and can see this as parsing the whole thing out into words then adding up words.

Still, only Daren knows how fast it needs to be. Many times the difference isn't that much. Many times for me it comes down to what I understand best. For me if it works usually everyone is happy. Something like this if I had the time might intrigue me to test it all 3 ways on a huge chunk of data. I'd have the program time itself.

It goes without saying you are correct of course on the need for error detection. Interesting you should point out "words" larger than 70. That's an error a lot of folks could overlook but the could occur.

This conversation on the fastest way makes me think of something I've noticed over the years. Please note, I don't condone this and I have NOT done this, on purpose, before. Throwing together a slow app that gets the job done wins you praise for getting the program written quickly. Wait till they grumble it's slow and then throw in a faster routine and your a hero again! I heard of a programmer who took this to the extreme. He built wait loops into his code to purposely slow it down. Months later when given the project to try to speed up the processing he say he'd try. Weeks later he was praised for making it so much faster. All he'd done was reduce the number of iterations his code spent in the wait loops. Makes you sick doesn't it? Of course this only works if your the only one that sees the code! I think that's how he got caught.

What have I learned from these observations and this fellow? People want the job done NOW. It's what I'm paid for. I do the best I can making sure it's done within the time alloted. Everyone's happy. (Except me, I'm rarely happy with my code but the realization that getting it done even if not the best way IS doing my job helps me cope.) I then continue to work on the code as I have time until I get it right and put in the changes. Of course if you follow my lead on this, make darn sure you are improving things with your changes. You don't want to introduce bugs into something that's working.


Joergen Bech <jbech<NOSPAM>@ wrote:
Another comment about your source sample: In your sample,
you remove the lines you found from the original string.
This is easy to read, but is likely to be costly in terms of
performance.
Instead, do not modify the original string at all during the loop,
but just keep track of where your next line begins, i.e. last
line end found becomes the next line start position.
If you are just testing it with a single paragraph or page,
you are unlikely to see any effect of this optimization, but
if you are writing an eBook converter or high-volume data
import function, it could be noticable.

Two more comments:

1) After you find your lines, make sure you trim them.

2) Make sure your algorithm handles lines with
"words" that are longer than the line length specified.
I haven't checked, but I am fairly sure the posted
sample would enter an infinite loop if such a beast
was encountered.
Yes, this could happen. Or have you never seen something
like

klajsdflkajsdflkjasdklfjaslkjdflkjasdlkjfkasdfjklasdjklflkjadskljfklasdflkjlkjasdflkjlkajsdfljkasjkldfjklalsdkjflkjasdflkjalkjsdflkjalskjfdlkjasdlkjfjkladflkjalkjsdflkjasdfljkalsdkjfjlafdljkakljfd

in a text file?

/JB



.



Relevant Pages

  • Re: Multiplicity, Change and MV
    ... as a String, for example. ... A lecturer teaches more than one course. ... As to your comment about loops, Mr Badour's comments and your question about ... different primary keys) the representation within the file structure is much ...
    (comp.databases.theory)
  • Re: Trouble Using System.Array.ForEach
    ... both a loop and an if-then, as well as some string manipulation. ... loops are very important and useful, but in this case I think I could do ... Nathan Sokalski ... I am trying to avoid) or the ForEach method. ...
    (microsoft.public.dotnet.languages.vb)
  • RE: VBA output to text editor
    ... just running empty loops took 2-3 ... RecA As String * 2 ... Sub BuildFile() ... Dim e As Integer, f As Integer, i As Long ...
    (microsoft.public.excel.programming)
  • Re: text compare takes very long...
    ... b1 = StrConv(String1, vbFromUnicode) ... In the earlier versions (where the loops in the main ... algorithm were equal to the product of the two string lengths) it would be ... loops in the new algorithm are much less than the product of the two string ...
    (microsoft.public.vb.general.discussion)
  • Re: Form Based Cross Tab Query
    ... Allan ... that loops through ... >the function returns a zero length string. ... > Dim strWhere as String ...
    (microsoft.public.access.queries)