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 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
"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/>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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"...
|
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,...
| |
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....
|
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...
|
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...
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |