|
OK - and this isn't a programming answer.
Do it backwards:
find out how many instances there are of the undesired substring.
find out how many instances there are of the base sting in all forms.
Do that math. Or I missed something in this.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
W∴ Balboos, GHB wrote: Do it backwards:
Interesting - a good solution, however, what I was really curious about is, how would you state the requirement, regardless of the optimization of the algorithm?
W∴ Balboos, GHB wrote: find out how many instances there are of the base sting in all forms.
Hah. That's actually much more elegant than my "IndicesOf" implementation!
|
|
|
|
|
Marc Clifton wrote: So, given a string, I want to verify that any instance of "foo" in the string is not a specific instance of "foobar."
You already did it!
|
|
|
|
|
Regular Expressions. Done.
|
|
|
|
|
I have only used regex in the past for tasks like this. Unlike most people, I am not scared of regex. Not sure if that is something you would be willing to tackle, but it would do exactly what you appear to want to do.
|
|
|
|
|
Have you considered splitting the string, using x+z as the delimiter? Then on each chunk you get back you can search for occurrences of x
Real programmers use butterflies
|
|
|
|
|
I think, given that the respondents so far seem to have clearly understood what you want, that you don't really have a problem; just specify it as you did in your opening sentence.
And yes, use Regex. (You could argue that the neatest functional definition of your requirement is simply the regex expression...) Who says the functional spec has to be written in English? RegEx is more widely understood around the world, and less ambiguous, after all...
|
|
|
|
|
DerekT-P wrote: given that the respondents so far seem to have clearly understood what you want
Actually no, they didn't. What I wanted was a "requirements statement", not a solution.
As in, is there a simpler way of saying what I said in my post?
|
|
|
|
|
We're all problem solvers, not linguists.
|
|
|
|
|
Exactly - they understood what you wanted to say. If it ain't broke, don't fix it - so go with the description you gave us. (Or, as I suggested, use a more precise language than English, such as RegEx).
|
|
|
|
|
"I want a count of the instances of the substring x, excluding the instances of substring x that is immediately followed by substring z"
|
|
|
|
|
Find all the instances of the string "X" that are not contained in the string "XY"?
Find all the instances of a string that can't be found in a concrete bigger string?
Find all the instances of a string "X" excluding the matches used in the string "XY"?
Find all the instances of a string "X" ignoring it if included in the string "XY"?
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 26-Jan-21 16:54pm.
|
|
|
|
|
Split source string on spaces and punctuation; then scan for target string in the resultant array; counting the number of occurrences.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
In light of "smartphones", Fauxbook, Twitfart, &etc., I suggest that Marshall McLuhan preposition be given a proper FIFY: "The medium is the message"
And I am aware of the irony of using FIFY in this post
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
. . . when archeologist dig up and unlock computer data from our time, they'll come across a significant number of instances of "Lorem ipsum dolor . . . ". It will be found often enough to be deemed a very important tome and decades will be spent by hoards of scholars attempting to translate it.
As we'll be well composted by then, I'll enjoy my laugh now.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
You wait until they finish with that and try to make sense of Farcebook and Twatter!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I see your point but you forgot to take into account that the "Cause of the Great Fall and Return Into Darkness" - as those two are referred to, historically, after their merger and expansion to broadcast services, was well documented.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
|
"Fat" lot of good that will do! In fact, by comparison I prefer OG's connection to extinction.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Actually, it's not that hard. "Lorem ipsum dolor . . . " - distorted version of Cicero book passage. It's Latin with deliberately made mistakes.
|
|
|
|
|
You'd think spellcheck or autocorrect would take care of that.
|
|
|
|
|
GenJerDan wrote: spellcheck or autocorrect They, too, will take their toll on the archeologists of the future.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
And no doubt will become the basis of a popular religion as it conveniently gets translated to a list of things common folk should never do.
|
|
|
|
|
I like the way you think. Can we monetize this yet?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Why not? L. Ron Hubbard did something similar...
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|