473,499 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No Recursive instr?!!

I must have missed it. It cannot be possible. Or may be I am living in the
past of my lisp programming days.

There must be a function to find the nth occurrence of a string within
another. instr only gives you the first one. Of course I can write a
function that recurses n times to get the nth occurrence, but there must be
a native version, right? To clarify, lets say I want the 3rd x in this
string:

strMine="xxoooxoxoxo"

instrNth=(strMine, "x", 3)
returning 6

Any ideas?
--
Anil Gupte
www.keeninc.net
www.icinema.com
Sep 26 '06 #1
3 2015

Depending on your case, I guess you can profit from regex? e.g.:

dim re as regex = new regex(pattern, regexoptions.multiline) ' e.g.
pattern = "x"
dim myMatches as matchcollection = re.matches(source-string) 'e.g.
source-string = "xxooxoxoxo"

myMatches(n) = n'th occurrence of some match 'e.g. myMatches(2) = x
myMatches(n).index = the index of the n'th occ. 'e.g.
myMatches(2).index = 4

anyway - it's more pretty than writing a recursive instr function, I
guess...

Anil Gupte skrev:
I must have missed it. It cannot be possible. Or may be I am living in the
past of my lisp programming days.

There must be a function to find the nth occurrence of a string within
another. instr only gives you the first one. Of course I can write a
function that recurses n times to get the nth occurrence, but there must be
a native version, right? To clarify, lets say I want the 3rd x in this
string:

strMine="xxoooxoxoxo"

instrNth=(strMine, "x", 3)
returning 6

Any ideas?
--
Anil Gupte
www.keeninc.net
www.icinema.com
Sep 26 '06 #2
"Anil Gupte" <an*******@icinema.comschrieb:
>I must have missed it. It cannot be possible. Or may be I am living in
the past of my lisp programming days.

There must be a function to find the nth occurrence of a string within
another. instr only gives you the first one. Of course I can write a
function that recurses n times to get the nth occurrence, but there must
be a native version, right? To clarify, lets say I want the 3rd x in this
string:
I'd use the iterative approach: Call 'InStr' until either the end of the
string is reached or the n-th occurance has been found.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 26 '06 #3
Wow! Regex is quite comprehensive - I will have to sit down and study it
for a while, before I can use it.

Thanx!
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Maate" <mo****@m8solutions.dkwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Depending on your case, I guess you can profit from regex? e.g.:

dim re as regex = new regex(pattern, regexoptions.multiline) ' e.g.
pattern = "x"
dim myMatches as matchcollection = re.matches(source-string) 'e.g.
source-string = "xxooxoxoxo"

myMatches(n) = n'th occurrence of some match 'e.g. myMatches(2) = x
myMatches(n).index = the index of the n'th occ. 'e.g.
myMatches(2).index = 4

anyway - it's more pretty than writing a recursive instr function, I
guess...

Anil Gupte skrev:
>I must have missed it. It cannot be possible. Or may be I am living in
the
past of my lisp programming days.

There must be a function to find the nth occurrence of a string within
another. instr only gives you the first one. Of course I can write a
function that recurses n times to get the nth occurrence, but there must
be
a native version, right? To clarify, lets say I want the 3rd x in this
string:

strMine="xxoooxoxoxo"

instrNth=(strMine, "x", 3)
returning 6

Any ideas?
--
Anil Gupte
www.keeninc.net
www.icinema.com

Sep 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
309860
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
0
1933
by: David | last post by:
Please help. I am able to display a folder structure and files but I can't figure out how to add subfolders and maintain the same look. I am a little embarrased but I thought someone out there...
7
3243
by: GysAnn | last post by:
Hello, I'm looking for a function for converting the input to a regular text. Example: when the input is "aBCdefgHI jkLM ooPP" the return value of the function should be "Abcdefghi Jklm...
6
3992
by: Chris Calzaretta | last post by:
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"...
4
1977
by: Gordon | last post by:
Hi; I am trying to extract a substring using a combination of the mid() and Instr() i.e. aString = "Jones, Thomas R, Dr." hold = InStr(1, aString, " ," , 1) newString = Mid(aString, 1,...
4
3905
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
2947
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
3
2609
by: lstrudeman | last post by:
Hello; A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and...
3
2229
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.