Prev: Combobox Showing Right Justified
Next: Can't make exe
From: Cor Ligthert[MVP] on 23 Mar 2010 14:07 Sage, I agree with you, I made two mistakes in my original code, however I had two intentions. To show the fine Split and Join functions, which are a main part of the Microsoft Visual Basic program language which were as far as I can see not showed yet and for me vital for the question from the OP. (The replace is an element of almost every program language, that is probably even in the book Visual Basic for Dummies.) And to show the false information given here about the progress of the Visual Basic program language, where here still after 8 years is lied about the progress of VB. There are more changes between VB5 and VB6 then in any version behind that. In fact is for all managed code program languages the IDE used, which comes from VB6 (not C++). So what is wanted her, that Steve Ballmer goes on his knees to some persons here and tell them that those were right and was wrong? For the rest, do I not like in this newsgroup about newer versions of VB. I have enough places where I can do that with a better audience. Cor "Saga" <antiSpam(a)nowhere.com> wrote in message news:#dbcLAryKHA.5332(a)TK2MSFTNGP02.phx.gbl... > Hi Cor, I did not mean to nitpick - that was not my intention. It > is important to understand that many that come here are beginners > and most likely will not know the difference between inadvertently > declaring a variant and declaring a string and the optimization issues > of these two data types. This is why we should test the code before > we (and I *really* include myself here) post and also make a best > effort to post good code so that bad programming habits are not > picked up by the newcomers to this (or any other) language. This > is in contrast to examples provided by MS itself where certain > "really-bad" VB statements are used. Regards, Saga > > > "Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote in message > news:OmlDWJmyKHA.4156(a)TK2MSFTNGP06.phx.gbl... >> But explaining why the original code would not run would've been more >> helpful. It would go like this in VB6. I was perplex from your reply. >> So I made the most easy code, it could also have been. >> >> Dim b() As String >> Dim a As String >> a = "Hello World" >> a = Replace(a, " ", " ") >> b = Split(a, " "). >> >> But from some like you seems to be more focused on nitpicking in this >> newsgroup then to try be real helpful with replies. >> >> It is in fact not a VB problem, but because of that Nxt has two methods >> Split and Replace in what is called in Nxt namespaces. >> >> However, that it is not a VB problem does not change that it will not >> compile (build) in later versions of VB, without adding that strings. >> >> Cor >> >> "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote in message >> news:eOYQ7AhyKHA.404(a)TK2MSFTNGP02.phx.gbl... >>> >>> "Michel Posseth [MCP]" <msdn(a)posseth.com> wrote in message >>> news:FDB5A490-AC89-487C-98CA-A883FEBC0B7F(a)microsoft.com... >>> >>>>>> [Cor Ligthert said] >>>>>> Dim b >>>>>> Dim a >>>>>> a = "Hello World" >>>>>> You mean this wont not compile in any way in VB6? >>>> >>>>> [Saga said] Technically, it will compile in VB6, but the >>>>> above is not the best approach to . . . >>>> >>>> [Michel Posseth said] No Mike is right it wouldn`t even compile >>>> unless if you have Option explicit OFF and the "require variable >>>> declarion setting"switched to the OFF position in the General tab >>>> of the options dialogbox otherwise VB6 wil enforce a type >>>> declaration , and wich self respecting professional coder whould >>>> code with these settings ? ;-) >>> >>> You're wrong there, Michel, and I think you've got hold of the wrong end >>> of the stick as well. I never said that the above code would not >>> compile. In fact if you read carefully what I actually posted in >>> response to the message which contained that code you will see that I >>> said it /would/ compile, but that it was /not/ the code Cor Ligthert had >>> originally posted when I had previously said it would not. >>> >>> Cor was trying to cover his tracks by querying a statement of mine, >>> which was perfectly true, by changing his previously posted code and by >>> dishonestly pretending to paraphrase it when he repeated his question, >>> hoping that it would not be noticed. So Saga is quite right in saying >>> that Cor Ligthert's latest attempt (as shown above) would compile, and >>> he is of course also quite right in saying that it is not the best >>> approach (for the various reasons he quoted, including the fact that it >>> would default to the Variant data type). >>> >>> Contrary to what you have stated, Michel, VB does /not/ enforce a type >>> declaration in such cases, regardless of whether you are using Option >>> Explicit or not and regardless of the setting of the "Require Variable >>> Declaration" check box in the Options dialog. Option Explicit forces you >>> to declare a variable, but it does not force you to declare its type. >>> All that will happen if you fail to declare its type is that VB will >>> cause the type to default to a Variant. So, Both Saga and myself were >>> correct in saying that Cor Ligthert's latest attempt would actually >>> compile (although his previous attempts would not). >>> >>> Mike >>> >>> > >
From: Larry Serflaten on 23 Mar 2010 15:55 "Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote > In this case the best solution is in my idea the one I gave, and if there > can be more than two spaces (which was not in the question from the OP), to > use a replace with a loop or if it is a huge string, going thru it with an > Instr which is than at least 70 times quicker than a Regex. Here are the OP's words: <QUOTE> here's an example of a string I have. "8 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 8.14 8.15 8.16 8.17 8.18 8.19 8.20 8.21 8.22 8.23 8.24 8.25 8.26" and ultimately here what I would like "8,8.1,8.2,8.3,8.4,8.5,8.6,8.7,8.8,8.9,8.10,8.11,8.12,8.13,8.14,8.15,8.16,8.17,8.18,8.19,8.20,8.21,8.22,8.23,8.24,8.25,8.26" </QUOTE> Replacing spaces in that input would not produce the desired output. All the arguing about .Nxt code vs. VB6 code was useless to the OP because neither of them addressed his problem. His input did not have spaces as was originally posted, upon clarification it was learned his input had carriage returns! So... my solution was the best.... :-) LFS
From: Saga on 23 Mar 2010 16:31 >By the way... I just tested your theory... The regex is almost 3 >times faster then using the loop/replace method, and only required one >line of code. So, I guess I'll stick to my way for now, unless I need >speed - the loop/stringbuilder method was about twice as fast as the >regex. >-- >Tom Shelton Digressign from themain topic... Interesting. Can you post the code that you used to test? I would like to take this topic further. Wait a second.. I just reread you text. Am I not understanding something or are your statements in conflict? "The regex is almost 3 times faster then using the loop/replace method..." "...the loop/stringbuilder method was about twice as fast as the regex." Which is correct? Thanks! Saga
From: Tom Shelton on 23 Mar 2010 17:00 On 2010-03-23, Saga <antiSpam(a)nowhere.com> wrote: > >>By the way... I just tested your theory... The regex is almost 3 >>times faster then using the loop/replace method, and only required one >>line of code. So, I guess I'll stick to my way for now, unless I need >>speed - the loop/stringbuilder method was about twice as fast as the >>regex. > >>-- >>Tom Shelton > > Digressign from themain topic... > > Interesting. Can you post the code that you used to test? I would like > to take this topic further. > I could... But, I'm not going to :) Simply because it's already digressed to far. The methods are .NET methods, and I really don't want to be caught up in anymore of this back and forth stuff. These discussions have been going on for 10 years now. I happend across an archive the other day of a discussion that occured back in 2000. Some of the same people (my self included) , same arguments. Just not worth it anymore. After a decade, people have made their choices and there's really no use discussing it futher. If I post my code, here, then it will just further irritate the regulars. > Wait a second.. I just reread you text. Am I not understanding something > or are your statements in conflict? > I timed 3 methods. One using a regex to normalize whitespace, one to use basically the original version posted by mike with a do loop/replace, and one using a stringbuilder as a buffer to build a new string. The version using the regex was about 3 times faster then the do loop/replace method. The version using the stringbuilder was about twice as fast as the version usign the regex. I shouldn't really have said anything at all, except that Cor's numbers on the relative speed of the VB.NET string functions vs RegEx struck me as odd - considering the overhead that the VB functions impose on top of the native string methods. -- Tom Shelton
From: Henning on 23 Mar 2010 17:16
"Larry Serflaten" <serflaten(a)usinternet.com> skrev i meddelandet news:uSw02oryKHA.5576(a)TK2MSFTNGP05.phx.gbl... > > "Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote > >> In this case the best solution is in my idea the one I gave, and if there >> can be more than two spaces (which was not in the question from the OP), >> to >> use a replace with a loop or if it is a huge string, going thru it with >> an >> Instr which is than at least 70 times quicker than a Regex. > > Here are the OP's words: > > <QUOTE> > here's an example of a string I have. > "8 > > > 8.1 > 8.2 > 8.3 > 8.4 > 8.5 > 8.6 > 8.7 > 8.8 > 8.9 > 8.10 > 8.11 > 8.12 > 8.13 > 8.14 > 8.15 > 8.16 > 8.17 > 8.18 > 8.19 > 8.20 > 8.21 > 8.22 > 8.23 > 8.24 > 8.25 > 8.26" > > and ultimately here what I would like > "8,8.1,8.2,8.3,8.4,8.5,8.6,8.7,8.8,8.9,8.10,8.11,8.12,8.13,8.14,8.15,8.16,8.17,8.18,8.19,8.20,8.21,8.22,8.23,8.24,8.25,8.26" > </QUOTE> > > Replacing spaces in that input would not produce the desired output. > > All the arguing about .Nxt code vs. VB6 code was useless to the OP > because neither of them addressed his problem. His input did not have > spaces as was originally posted, upon clarification it was learned his > input had carriage returns! > > So... my solution was the best.... :-) > > LFS > Ehrrrmmm, you never read my solution ( a lot of posts up) then ;) Focusing not on what to remove, but on what to keep. /Henning |