|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
InStr anomaly?InStr("ADEG",string2)
OK if string2 is something like Z, gives result 0 as expected but if string2 is "", gives 1! "Aalaan" <veryinva***@invalid.com> wrote in message Where would you say that the first occurrence of a zero-length string is?news:45e85cf3$1@dnews.tpgi.com.au > InStr("ADEG",string2) > > OK if string2 is something like Z, gives result 0 as expected but if > string2 is "", gives 1! It could be argued either way. Test the length of string2 and handle it as you need. -- Reply to the group so all can participate VB.Net: "Fool me once..." "Bob Butler" <tiredofit@nospam.ever> wrote Its at the 0th position isn't it???> > InStr("ADEG",string2) > > > > OK if string2 is something like Z, gives result 0 as expected but if > > string2 is "", gives 1! > > Where would you say that the first occurrence of a zero-length string is? ? Instr("", "") ' 0 <g> LFS "Bob Butler" <tiredofit@nospam.ever> wrote in message Well I certainly would not say that the zero length string is at position 1 news:u6EPAAPXHHA.528@TK2MSFTNGP03.phx.gbl... > Where would you say that the first occurrence of a zero-length string is? in the example which Alan posted (InStr("ADEG",string2)). If, as you suggest, the "empty string" is at position 1, and if a separate test for (Instr("ADEG",string2)) tells us that "A" is at position 1 (which of course it will do) then VB must be telling us that "A" is an empty string!!! Mind you, I suppose we could argue that there are an infinite number of empty strings at every character position, as well as the "real" character which occupies that position. The mind boggles ;-) Mike p.s. I have actually just double checked the help files and it does actually say that the value of Start will be returned if string2 is an empty string, an the example actually does comply with that, so VB is returing what the help files tell us it will return. I still think it is very strange though for VB to tell us that "A" is an empty string ;-) >> Where would you say that the first occurrence of a zero-length string is? I'm not sure why this bothers you... it seems like there is nothing to it to > > Well I certainly would not say that the zero length string is at position > 1 in the example which Alan posted (InStr("ADEG",string2)). If, as you > suggest, the "empty string" is at position 1, and if a separate test for > (Instr("ADEG",string2)) tells us that "A" is at position 1 (which of > course it will do) then VB must be telling us that "A" is an empty > string!!! Mind you, I suppose we could argue that there are an infinite > number of empty strings at every character position, as well as the "real" > character which occupies that position. The mind boggles ;-) me.<g> Rick Rick Rothstein (MVP - VB) wrote:
> I'll tell you what bothers ME. But it'll take me a few lines to get to that...> I'm not sure why this bothers you... it seems like there is nothing to it to > me.<g> > Expecting there to be anything philosophically consistent across all the possible results is foolishness. All that matters is that the function does what the docs say it will do. Unfortunately, in my help files, it badly *misstates* one relevant rule (the last one, below) which should have been more like: start > len(string1) 0 (which could actually replace both the first and last of the rules listed) =========(MSDN Oct 2001)======== Return Values If InStr returns string1 is zero-length 0 string1 is Null Null string2 is zero-length start string2 is Null Null string2 is not found 0 string2 is found within string1 Position at which match is found start > string2 0 ========= How the heck could "start > string2" get in there???????? Bob -- Bob O`Bob wrote:
> And that table is THE SAME in my VB5 and VB4(16bit) help files!!!!!!!!> How the heck could "start > string2" get in there???????? > There's no table in the VB3 help for InStr, but it makes THE SAME assertion in text: If strexpr2 is found within strexpr1, InStr returns the position at which the match was found. If strexpr2 is zero-length, start is returned. If start is greater than strexpr2, strexpr1 is zero-length, or strexpr2 can't be found, InStr returns 0. Either the world has been retroactively messed with, or we've all missed that for YEARS. Or else I'm horribly misinterpreting it today??????? "If start is greater than strexpr2" ... how could that /ever/ have been sensible???? Bob -- Good point there. I know I've read the docs before, and I just absorbed
what was meant...not what was VERY badly misstated. Rob Show quoteHide quote "Bob O`Bob" <filter***@yahoogroups.com> wrote in message news:upOUGxQXHHA.496@TK2MSFTNGP06.phx.gbl... > Rick Rothstein (MVP - VB) wrote: >> >> I'm not sure why this bothers you... it seems like there is nothing to it >> to me.<g> >> > > I'll tell you what bothers ME. But it'll take me a few lines to get to > that... > > > Expecting there to be anything philosophically consistent across all > the possible results is foolishness. > > All that matters is that the function does what the docs say it will do. > > > > > Unfortunately, in my help files, it badly *misstates* one relevant rule > (the last one, below) which should have been more like: > > start > len(string1) 0 > > (which could actually replace both the first and last of the rules listed) > > > > =========(MSDN Oct 2001)======== > Return Values > > If InStr returns > string1 is zero-length 0 > string1 is Null Null > string2 is zero-length start > string2 is Null Null > string2 is not found 0 > string2 is found within string1 Position at which match is found > start > string2 0 > > > ========= > > > How the heck could "start > string2" get in there???????? > > > > > Bob > --
Show quote
Hide quote
"Bob O`Bob" <filter***@yahoogroups.com> skrev i meddelandet I think of it as a select case, first true case is used.news:upOUGxQXHHA.496@TK2MSFTNGP06.phx.gbl... > Rick Rothstein (MVP - VB) wrote: > > > > I'm not sure why this bothers you... it seems like there is nothing to it to > > me.<g> > > > > I'll tell you what bothers ME. But it'll take me a few lines to get to that... > > > Expecting there to be anything philosophically consistent across all > the possible results is foolishness. > > All that matters is that the function does what the docs say it will do. > > > > > Unfortunately, in my help files, it badly *misstates* one relevant rule > (the last one, below) which should have been more like: > > start > len(string1) 0 > > (which could actually replace both the first and last of the rules listed) > > > > =========(MSDN Oct 2001)======== > Return Values > > If InStr returns > string1 is zero-length 0 > string1 is Null Null > string2 is zero-length start > string2 is Null Null > string2 is not found 0 > string2 is found within string1 Position at which match is found > start > string2 0 > > > ========= > > > How the heck could "start > string2" get in there???????? > > > > > Bob > -- /Henning > Unfortunately, in my help files, it badly *misstates* one relevant rule I don't find that troublesome at all... it simply says if you ask the > (the last one, below) which should have been more like: > > start > len(string1) 0 > > =========(MSDN Oct 2001)======== > Return Values > > If InStr returns > start > string2 0 > > How the heck could "start > string2" get in there???????? function to start looking for a substring beyond the end of the string, it won't find it. Rick
Show quote
Hide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in Read it closely: String2, not String1message news:%23cSE08RXHHA.4480@TK2MSFTNGP04.phx.gbl >> Unfortunately, in my help files, it badly *misstates* one relevant >> rule (the last one, below) which should have been more like: >> >> start > len(string1) 0 >> >> =========(MSDN Oct 2001)======== >> Return Values >> >> If InStr returns >> start > string2 0 >> >> How the heck could "start > string2" get in there???????? > > I don't find that troublesome at all... it simply says if you ask the > function to start looking for a substring beyond the end of the > string, it won't find it. -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
Hide quote
"Bob Butler" <tiredofit@nospam.ever> wrote in message Duh! I missed that. It must have been a typo that wasn't caught originally news:%23j$yw$RXHHA.4076@TK2MSFTNGP05.phx.gbl... > "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in > message news:%23cSE08RXHHA.4480@TK2MSFTNGP04.phx.gbl >>> Unfortunately, in my help files, it badly *misstates* one relevant >>> rule (the last one, below) which should have been more like: >>> >>> start > len(string1) 0 >>> >>> =========(MSDN Oct 2001)======== >>> Return Values >>> >>> If InStr returns >>> start > string2 0 >>> >>> How the heck could "start > string2" get in there???????? >> >> I don't find that troublesome at all... it simply says if you ask the >> function to start looking for a substring beyond the end of the >> string, it won't find it. > > Read it closely: String2, not String1 (and simply copied over from version to version thereafter). Rick Not to mention that it should have said start > LEN(String1), not start >
String1. Rob Show quoteHide quote "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message news:uZ2jWDSXHHA.4216@TK2MSFTNGP02.phx.gbl... > > "Bob Butler" <tiredofit@nospam.ever> wrote in message > news:%23j$yw$RXHHA.4076@TK2MSFTNGP05.phx.gbl... >> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in >> message news:%23cSE08RXHHA.4480@TK2MSFTNGP04.phx.gbl >>>> Unfortunately, in my help files, it badly *misstates* one relevant >>>> rule (the last one, below) which should have been more like: >>>> >>>> start > len(string1) 0 >>>> >>>> =========(MSDN Oct 2001)======== >>>> Return Values >>>> >>>> If InStr returns >>>> start > string2 0 >>>> >>>> How the heck could "start > string2" get in there???????? >>> >>> I don't find that troublesome at all... it simply says if you ask the >>> function to start looking for a substring beyond the end of the >>> string, it won't find it. >> >> Read it closely: String2, not String1 > > Duh! I missed that. It must have been a typo that wasn't caught originally > (and simply copied over from version to version thereafter). > > Rick > Rick Rothstein (MVP - VB) wrote:
Show quoteHide quote >> Unfortunately, in my help files, it badly *misstates* one relevant But it says string2, not string1>> rule (the last one, below) which should have been more like: >> >> start > len(string1) 0 >> >> =========(MSDN Oct 2001)======== >> Return Values >> >> If InStr returns >> start > string2 0 >> >> How the heck could "start > string2" get in there???????? > > I don't find that troublesome at all... it simply says if you ask the > function to start looking for a substring beyond the end of the > string, it won't find it. By that rule, InStr(4, "ABCDEFG", "FG") would return 0 -- Jim "Mike Williams" <m***@whiskyandCoke.com> wrote in message Which is why Instr(1,"","") is an anomalynews:et1XR3PXHHA.1120@TK2MSFTNGP02.phx.gbl > p.s. I have actually just double checked the help files and it does > actually say that the value of Start will be returned if string2 is > an empty string, an the example actually does comply with that, so VB > is returing what the help files tell us it will return. I still think > it is very strange though for VB to tell us that "A" is an empty > string ;-) -- Reply to the group so all can participate VB.Net: "Fool me once..." "Bob Butler" <tiredofit@nospam.ever> wrote in message Exactly. If, as some people have said, VB regards the first empty string as news:Of7vPdQXHHA.2256@TK2MSFTNGP02.phx.gbl... > Which is why Instr(1,"","") is an anomaly being at position 1 then the above code should have found it there! However, according to the help files, if String1 is zero length then the result of Instr is zero, and if String2 is zero length then Instr returns the value of Start. In the above example both conditions are true, therefore Instr(1,"","") should return both zero and 1 at the same time! Or perhaps in a parallel universe the reverse is true ;-) Curiouser and curiouser, said Alice :-) Mike Bob Butler wrote:
> "Mike Williams" <m***@whiskyandCoke.com> wrote in message I don't agree.> news:et1XR3PXHHA.1120@TK2MSFTNGP02.phx.gbl >> p.s. I have actually just double checked the help files and it does >> actually say that the value of Start will be returned if string2 is >> an empty string, an the example actually does comply with that, so VB >> is returing what the help files tell us it will return. I still think >> it is very strange though for VB to tell us that "A" is an empty >> string ;-) > > Which is why Instr(1,"","") is an anomaly > I already covered this in another part of the thread, but I have a definite recollection (my present help files be damned) that there's also a rule that 0 will be returned (regardless of string2) if start > len(string1) Bob --
Show quote
Hide quote
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message It's an anomaly when considering just how it handles string2 being ""; innews:eaXmlyQXHHA.496@TK2MSFTNGP06.phx.gbl > Bob Butler wrote: >> "Mike Williams" <m***@whiskyandCoke.com> wrote in message >> news:et1XR3PXHHA.1120@TK2MSFTNGP02.phx.gbl >>> p.s. I have actually just double checked the help files and it does >>> actually say that the value of Start will be returned if string2 is >>> an empty string, an the example actually does comply with that, so >>> VB is returing what the help files tell us it will return. I still >>> think it is very strange though for VB to tell us that "A" is an >>> empty string ;-) >> >> Which is why Instr(1,"","") is an anomaly >> > > I don't agree. > > I already covered this in another part of the thread, but I have a > definite recollection (my present help files be damned) that there's > also a rule that 0 will be returned (regardless of string2) if start > > len(string1) the more general case there's a conflict between 2 rules and the string="" rule is taking precedence. In any case I can think of it makes sense to test for string2 being zero-length external to the Instr since it dones' really make sense to search for nothing. -- Reply to the group so all can participate VB.Net: "Fool me once..." "Aalaan" <veryinva***@invalid.com> wrote in message This isn't an anomaly. This is absolutely logicalnews:45e85cf3$1@dnews.tpgi.com.au... > InStr("ADEG",string2) > > OK if string2 is something like Z, gives result 0 as expected but if > string2 is "", gives 1! When string2 is "", InStr can find it in any string. Think about it. If you are looking for nothing, you can find it anywhere. The Peasant "The Peasant" <nabux***@datag.co.uk> wrote in message One anomaly...news:O8YURIPXHHA.600@TK2MSFTNGP05.phx.gbl > "Aalaan" <veryinva***@invalid.com> wrote in message > news:45e85cf3$1@dnews.tpgi.com.au... >> InStr("ADEG",string2) >> >> OK if string2 is something like Z, gives result 0 as expected but if >> string2 is "", gives 1! > > This isn't an anomaly. This is absolutely logical > When string2 is "", InStr can find it in any string. > Think about it. If you are looking for nothing, you can find it > anywhere. Instr(1,"","") -- Reply to the group so all can participate VB.Net: "Fool me once..." >>> InStr("ADEG",string2) That is not really an anomaly... there is no first character in an empty >>> >>> OK if string2 is something like Z, gives result 0 as expected but if >>> string2 is "", gives 1! >> >> This isn't an anomaly. This is absolutely logical >> When string2 is "", InStr can find it in any string. >> Think about it. If you are looking for nothing, you can find it >> anywhere. > > One anomaly... > Instr(1,"","") string. This is no different than this statement... Instr(4, "abc", "a") However, the following IS an anomaly... Instr(5, "abc", "") as the string is only 3 characters long, 4 if you assume it ends with an empty string (unless we assume there are an unlimited number of empty string characters following any text string). Rick > That is not really an anomaly... there is no first character in an empty Of course, if we assume an unlimited number of empty string characters > string. This is no different than this statement... > > Instr(4, "abc", "a") > > However, the following IS an anomaly... > > Instr(5, "abc", "") > > as the string is only 3 characters long, 4 if you assume it ends with an > empty string (unless we assume there are an unlimited number of empty > string characters following any text string). following any text string, then that first example is an anomaly after all.<g> Rick "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in This is getting silly <bg>message news:eiOjckPXHHA.4240@TK2MSFTNGP06.phx.gbl... > Of course, if we assume an unlimited number of empty string > characters following any text string, then that first example is > an anomaly after all.<g> Mike Mike Williams wrote:
> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in It's been silly at least since the VB3 InStr help page was written.> message news:eiOjckPXHHA.4240@TK2MSFTNGP06.phx.gbl... > >> Of course, if we assume an unlimited number of empty string >> characters following any text string, then that first example is >> an anomaly after all.<g> > > This is getting silly <bg> > Bob -- Yes, I'm astounded at the tight loops some people are getting themselves
into. It seems to me obvious that if InStr("ABCD","A") = 1 (the position in string 1 of string 2) then it is anomalous that InsStr("ABCD,"") also = 1! Surely the argument that "ABCD" contains a number of "" is silly. Of course it can be trapped out but it's a pity that's necessary. As everyone here knows, I am of course a raw beginner at vb but this gets at pure logic surely (on the KISS principle -- before someone comes back with a long philosophical discourse asserting that any given string is made up from an infinite number of blanks...) Show quoteHide quote "Mike Williams" <mi***@whiskyandCoke.com> wrote in message news:uvoAuARXHHA.4252@TK2MSFTNGP06.phx.gbl... > "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in > message news:eiOjckPXHHA.4240@TK2MSFTNGP06.phx.gbl... > >> Of course, if we assume an unlimited number of empty string >> characters following any text string, then that first example is >> an anomaly after all.<g> > > This is getting silly <bg> > > Mike > > Murphy missed out a " on my second mention of "ABCD". Sorry.
Show quoteHide quote "Aalaan" <veryinva***@invalid.com> wrote in message news:45e8a148@dnews.tpgi.com.au... > Yes, I'm astounded at the tight loops some people are getting themselves > into. It seems to me obvious that if InStr("ABCD","A") = 1 (the position > in string 1 of string 2) then it is anomalous that InsStr("ABCD,"") also = > 1! Surely the argument that "ABCD" contains a number of "" is silly. Of > course it can be trapped out but it's a pity that's necessary. As everyone > here knows, I am of course a raw beginner at vb but this gets at pure > logic surely (on the KISS principle -- before someone comes back with a > long philosophical discourse asserting that any given string is made up > from an infinite number of blanks...) > > "Mike Williams" <mi***@whiskyandCoke.com> wrote in message > news:uvoAuARXHHA.4252@TK2MSFTNGP06.phx.gbl... >> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in >> message news:eiOjckPXHHA.4240@TK2MSFTNGP06.phx.gbl... >> >>> Of course, if we assume an unlimited number of empty string >>> characters following any text string, then that first example is >>> an anomaly after all.<g> >> >> This is getting silly <bg> >> >> Mike >> >> > > "Mike Williams" <mi***@whiskyandCoke.com> wrote in message And an excellent illustration of the superiority of 'C'.news:uvoAuARXHHA.4252@TK2MSFTNGP06.phx.gbl... > "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in > message news:eiOjckPXHHA.4240@TK2MSFTNGP06.phx.gbl... > > > Of course, if we assume an unlimited number of empty string > > characters following any text string, then that first example is > > an anomaly after all.<g> > > This is getting silly <bg> > > Mike > The C/C++ language lawyer would merely say the behavior is "undefined", "implementation dependent", and all further conversation would be terminated by the moderator. Boorish, but efficient. -ralph <g> Hahaha...interesting. Makes sense in a way, though, since there's NO first
character to search from. PS, for those who don't feel like opening up a VB/VBA window, Instr(1,"","") = 0 Rob Show quoteHide quote "Bob Butler" <tiredofit@nospam.ever> wrote in message news:OlwrfaPXHHA.1036@TK2MSFTNGP03.phx.gbl... > "The Peasant" <nabux***@datag.co.uk> wrote in message > news:O8YURIPXHHA.600@TK2MSFTNGP05.phx.gbl >> "Aalaan" <veryinva***@invalid.com> wrote in message >> news:45e85cf3$1@dnews.tpgi.com.au... >>> InStr("ADEG",string2) >>> >>> OK if string2 is something like Z, gives result 0 as expected but if >>> string2 is "", gives 1! >> >> This isn't an anomaly. This is absolutely logical >> When string2 is "", InStr can find it in any string. >> Think about it. If you are looking for nothing, you can find it >> anywhere. > > One anomaly... > Instr(1,"","") > > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > "The Peasant" <nabux***@datag.co.uk> wrote Really?> Think about it. If you are looking for nothing, you can find it anywhere. I could just as easily say, you can never find 'nothing'; everywhere you look, there is something there. LFS "The Peasant" stated...
: If you are looking for nothing, you find it anywhere. "Larry Serflaten" replied...: Really? No one ever finds nothing.: : I could just as easily say, you can never find 'nothing'; : everywhere you look, there is something there. That kind of reminds me of... Terence Hill as Nobody in "My Name Is Nobody". -- Jim Carlock Post replies to the group. This is a bit like that speech about not knowing what we don't know but
knowing that we don't know everything that we should know... Show quoteHide quote "Jim Carlock" <anonymous@localhost> wrote in message news:ucljKKRXHHA.1396@TK2MSFTNGP05.phx.gbl... > "The Peasant" stated... > : If you are looking for nothing, you find it anywhere. > > > "Larry Serflaten" replied... > : Really? > : > : I could just as easily say, you can never find 'nothing'; > : everywhere you look, there is something there. > > No one ever finds nothing. > > That kind of reminds me of... > > Terence Hill as Nobody in "My Name Is Nobody". > > -- > Jim Carlock > Post replies to the group. > >
using Line Input
Stop loading data process Application crashing - trying to track down the problem. Convert decimal to fraction string Looking for an easy way to achive this problem. email attachments? Vb6 to check if a text file is already opened Server my program is trying to connect to is not a trusted site with XP? Date Picker Control Read/Write permission (earn your quarter, Karl!) |
|||||||||||||||||||||||