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="xxooox oxoxo"
instrNth=(strMi ne, "x", 3)
returning 6
Any ideas?
--
Anil Gupte www.keeninc.net www.icinema.com 3 2024
Depending on your case, I guess you can profit from regex? e.g.:
dim re as regex = new regex(pattern, regexoptions.mu ltiline) ' e.g.
pattern = "x"
dim myMatches as matchcollection = re.matches(sour ce-string) 'e.g.
source-string = "xxooxoxoxo "
myMatches(n) = n'th occurrence of some match 'e.g. myMatches(2) = x
myMatches(n).in dex = the index of the n'th occ. 'e.g.
myMatches(2).in dex = 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="xxooox oxoxo"
instrNth=(strMi ne, "x", 3)
returning 6
Any ideas?
--
Anil Gupte www.keeninc.net www.icinema.com
"Anil Gupte" <an*******@icin ema.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****@m8solut ions.dkwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>
Depending on your case, I guess you can profit from regex? e.g.:
dim re as regex = new regex(pattern, regexoptions.mu ltiline) ' e.g.
pattern = "x"
dim myMatches as matchcollection = re.matches(sour ce-string) 'e.g.
source-string = "xxooxoxoxo "
myMatches(n) = n'th occurrence of some match 'e.g. myMatches(2) = x
myMatches(n).in dex = the index of the n'th occ. 'e.g.
myMatches(2).in dex = 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="xxooo xoxoxo"
instrNth=(strM ine, "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 some key
functionality I need. Here is an example of the Oracle code:
if Instr( sTg , cDelim, 1, 3 ) > 0 then
sd := SubStr( sTg, Instr( sTg , cDelim, 1, 1 ) + 1, Instr( sTg,
cDelim, 1, 2 ) - Instr( sTg , cDelim, 1, 1 ) - 1)
|
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 could help me out with this one.
Please email me at dkoopman@statestreet.com if you have a solution for me.
Thank you in advance,
Dave
<%@ Language=VBScript %>
|
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 Oopp"
Thanks in advance,
Anita
|
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"
instr(string1,">")
|
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, hold) + Mid(aString, hold + 2, InStr(hold + 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. ie "McCarthy,John Doe Willy". I have to split up Familyname and the 1st FirstName. The FamilyName works perfect, just looking up the comma with InStr and use Left().
Now can someone throw me a bone to help me get the 1st Firstname. "John" according...
|
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 ideas?
|
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 breaks apart the pieces of the key for other uses. The field looks like this 1234567*AWD*07FA (or 1234567*FPER*07FA). I just need to understand how the numbers behind the TA_2007_ID field work to break apart they key?? The first one is easy.. it just...
|
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 get this to only run on NON MISSING Project Dates?
Thanks!
Alex
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |