|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Hello Everybody,
Question instr function will give you the first instance of the finding so EX: so your string looks like string1 = "testing>This is > just a test > testtesttest" instr(string1,">") so instr will give me a 8 as a return item i need to get the last instance Easy way to do this. Thanks Chris Something like this
Untested Len(mystring) - InStr(StrReverse(mystring), ">") Richard Show quoteHide quote "Chris Calzaretta" <ccalzare***@hotmail.com> wrote in message news:O9fqPdUMFHA.4092@tk2msftngp13.phx.gbl... > Hello Everybody, > Question > > instr function will give you the first instance of the finding > so EX: > so your string looks like > > string1 = "testing>This is > just a test > testtesttest" > instr(string1,">") > > so instr will give me a 8 as a return item > i need to get the last instance > > > Easy way to do this. > > Thanks > Chris > Super easy!
Change "Instr" function to "InStrRev " function, which gets the position, starting from the right side of the string. Show quoteHide quote :) Chris,
When you want to use the Zero indexer ( I assume you don't want it however to get the answers complete than there is instead of the InStringRev as well the instruction). Don't expect any advantage from that, than that you are using the Zero as starting indexer instead of that you get back when it is on the first position a 1. dim pos as integer = String1.lastindexof(">") it gives a -1 when that is not in it. I hope this helps, Cor "Cor Ligthert" <notmyfirstn***@planet.nl> ha scritto nel messaggio Finally someone that uses the right .Net way instead of thenews:eSLhfTVMFHA.3852@tk2msftngp13.phx.gbl... > dim pos as integer = String1.lastindexof(">") old-fashoned-VB6-retro-compatibility functions, that aren't OOP and aren't so fast as native ones. Zanna,
> It is nice to wright that I am right, however I did not write this at all, >> dim pos as integer = String1.lastindexof(">") > > Finally someone that uses the right .Net way instead of the > old-fashoned-VB6-retro-compatibility functions, that aren't OOP and aren't > so fast as native ones. > > because it is not true. This is what I wrote (compressed) >>Don't expect any advantage from that, than that you are using the 0 as Cor>>starting >>indexer instead of the 1. "Cor Ligthert" <notmyfirstn***@planet.nl> ha scritto nel messaggio ???news:u8C9PX2MFHA.3392@TK2MSFTNGP10.phx.gbl... > It is nice to wright that I am right, however I did not write this at all, > because it is not true. You wrote the post or not? :) > This is what I wrote (compressed) Not just this, I can read :)> >>Don't expect any advantage from that, than that you are using the 0 as > >>starting > >>indexer instead of the 1. And sure InStr is sloooower than String.IndexOf, because calls wrapper functions from Microsoft.VisualBasic namespace. But my point was on the way you use VB.Net and not on the speed. Zanna,
> It is twice as fast as indexof, we tested that in this newsgroup about one > And sure InStr is sloooower than String.IndexOf, because calls wrapper > functions from Microsoft.VisualBasic namespace. > and an half year ago. Cor Do you have the test code that was used?
Show quoteHide quote "Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message news:%23ugrva5MFHA.2656@TK2MSFTNGP10.phx.gbl... > Zanna, > > > > > And sure InStr is sloooower than String.IndexOf, because calls wrapper > > functions from Microsoft.VisualBasic namespace. > > > It is twice as fast as indexof, we tested that in this newsgroup about one > and an half year ago. > > Cor > > JD,
See this thread http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/d9a3a1e441c5ef92/315c33cc87237dbf#315c33cc87237dbf However there is more. Cor In this example, for the InStr function, you don't specify the compare
method (binary or text). What was your "Option Compare" setting? The default on my project was binary. When InStr uses binary compare it does not take in effect culture info at all. The String.IndexOf always uses text and culture info on comparisons. If you were comparing both methods with InStr using binary, the test wasn't quite fair or accurate. When I changed InStr to use text compare, both InStr and String.IndexOf comparisons were roughly the same with InStr performing a little bit worse some of the time, at least on my machine. "Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/d9a3a1e441c5ef92/315c33cc87237dbf#315c33cc87237dbfnews:eP8Or65MFHA.3228@TK2MSFTNGP12.phx.gbl... > JD, > > See this thread > Show quoteHide quote > > However there is more. > > Cor > > JD,
I am not asking what is the fairest, the only question is. Can you let the indexof go as fast as the instr can go. The rest is a non isue. It is in my opinion quiet simple, the indexof has a lot of more overloads than the Instr what is a quiet simple method compared with the indexof. In addition, although that it is twice as slow do I use the indexof by the way, just because that zero indexer. Cor Hey Cor,
Question. What is the correct InStr answer for the following code? Dim str1 As String = "Æpple" Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US") Console.WriteLine(InStr(str1, "A")) 'this assumes binary compare is default option in the project settings Console.WriteLine(InStr(str1, "A", CompareMethod.Text)) Thanks Jeff Show quoteHide quote "Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message news:uTj26N8MFHA.244@TK2MSFTNGP12.phx.gbl... > JD, > > I am not asking what is the fairest, the only question is. Can you let the > indexof go as fast as the instr can go. The rest is a non isue. > > It is in my opinion quiet simple, the indexof has a lot of more overloads > than the Instr what is a quiet simple method compared with the indexof. > > In addition, although that it is twice as slow do I use the indexof by the > way, just because that zero indexer. > > Cor > > JD,
I interpretted your message wrong sorry. This is not only tested by me, there where more and I can tell you that at leaset I was very suprissed. I use forever indexof and never 1 starting indexer based methods. The indexof becomes much faster than the instr when it is about a character and you tell that it is a character in the parameters. Probably is the reason that Instr is a very simple method with no overloads (it has defaults), while the indexof is a very overloaded method and has therefore more to evaluate. That the Instr is faster than indexof is not a reason that other Microsoft VisualBasic namespace methods are faster as well. I have seen some which are very slow comparing with other commands. Cor "Cor Ligthert" <notmyfirstn***@planet.nl> ha scritto nel messaggio I don't understand your test, btw InStr and IndexOf are quite simplenews:#ugrva5MFHA.2656@TK2MSFTNGP10.phx.gbl... > > And sure InStr is sloooower than String.IndexOf, because calls wrapper > > functions from Microsoft.VisualBasic namespace. > > > It is twice as fast as indexof, > we tested that in this newsgroup about one > and an half year ago. functions (you can test their code with Reflector) so the speed in same conditions should be very close (I really don't believe the twice-story). But, as I sayd, the point is the way you write the code! As Martin Flower sayd "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". This means also that you shoud not use bad practices in your code, and using an old deprecated VB6-compliant non-OOP function I think can be put with the bad practices. Also the InStr is an example, but the same can be said for Mid$, Left$ and so on. Take VB.Net for the tool it is, and, it's sure, it's NOT VB7 Zanna,
> But, as I sayd, the point is the way you write the code! That is why my first sample in this thread was stated on.> Martin "wrote" it, in my memory this sentense exist much longer it is one of > As Martin Flower sayd "Any fool can write code that a computer can > understand. Good programmers write code that humans can understand". the basics of a good readable program. > This means also that you shoud not use bad practices in your code, and This has nothing to do with the previous sentence. "Instr" has as much to do > using > an old deprecated VB6-compliant non-OOP function I think can be put with > the > bad practices. with OOP as "indexof" has to do with OOP; Nothing, it are string evaluating methods.. > That is true,> Also the InStr is an example, but the same can be said for Mid$, Left$ and > so on. > > Take VB.Net for the tool it is, and, it's sure, it's NOT VB7 No however those methods you mention can be used in C# or whatever other Net > language as well. So why would I use them in C# and not in VBNet. They are an integrated part of the distributed framework. (Not the keywords as the Static value, those belong to VBNet). Cor "Cor Ligthert" <notmyfirstn***@planet.nl> ha scritto nel messaggio Well, I think you misunderstand what I'm sayng :)news:eztmuyCNFHA.1392@TK2MSFTNGP10.phx.gbl... > No however those methods you mention can be used in C# or whatever other Net > language as well. So why would I use them in C# and not in VBNet. They are > an integrated part of the distributed framework. (Not the keywords as the > Static value, those belong to VBNet). I told "use .IndexOf: IndexOf is better than InStr". The same you say in the phrase above. > I did nowhere write it is "better", when you see Hefried samples, than he is > Well, I think you misunderstand what I'm sayng :) > I told "use .IndexOf: IndexOf is better than InStr". > > The same you say in the phrase above. > forever using Mid, Right, Left in that case I would find it very incosequent to use indexof. Cor "Cor Ligthert" <notmyfirstn***@planet.nl> ha scritto nel messaggio I don't care about bad-coded-samples ;)news:#OQOnwDNFHA.1948@TK2MSFTNGP14.phx.gbl... > I did nowhere write it is "better", when you see Hefried samples, than he is > forever using Mid, Right, Left in that case I would find it very incosequent > to use indexof. :) Chris,
"Chris Calzaretta" <ccalzare***@hotmail.com> schrieb: 'Microsoft.VisualBasic.Strings.InStrRev'.> instr function will give you the first instance of the finding > so EX: > so your string looks like > > string1 = "testing>This is > just a test > testtesttest" > instr(string1,">") > > so instr will give me a 8 as a return item > i need to get the last instance -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Time Critical Process in .NET
HTML Forms Progamatically Via VB.NET Microsoft MVPs Say They Want Old VB Back Problem with VS.NET 2003 the menu and the shortcuts Converting MS Access 2000 application to a VB / VB.NET application Problem Compare Two File list item colour Error on break Help for VBnet Thread |
|||||||||||||||||||||||