By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

InStr

P: n/a
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,">")

so instr will give me a 8 as a return item
i need to get the last instance
Easy way to do this.

Thanks
Chris
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Super easy!

Change "Instr" function to "InStrRev " function, which gets the
position, starting from the right side of the string.

:)

Nov 21 '05 #2

P: n/a
Something like this

Untested
Len(mystring) - InStr(StrReverse(mystring), ">")

Richard

"Chris Calzaretta" <cc*********@hotmail.com> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...
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,">")

so instr will give me a 8 as a return item
i need to get the last instance
Easy way to do this.

Thanks
Chris

Nov 21 '05 #3

P: n/a
Chris,

When you want to use the Zero indexer ( I assume you don't want it however
to get the answers complete than there is instead of the InStringRev as well
the instruction). Don't expect any advantage from that, than that you are
using the Zero as starting indexer instead of that you get back when it is
on the first position a 1.

dim pos as integer = String1.lastindexof(">")
it gives a -1 when that is not in it.

I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
Chris,

"Chris Calzaretta" <cc*********@hotmail.com> schrieb:
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,">")

so instr will give me a 8 as a return item
i need to get the last instance


'Microsoft.VisualBasic.Strings.InStrRev'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

P: n/a
"Cor Ligthert" <no************@planet.nl> ha scritto nel messaggio
news:eS**************@tk2msftngp13.phx.gbl...

dim pos as integer = String1.lastindexof(">")


Finally someone that uses the right .Net way instead of the
old-fashoned-VB6-retro-compatibility functions, that aren't OOP and aren't
so fast as native ones.
--
Reporting tool: http://www.neodatatype.net
Nov 21 '05 #6

P: n/a
"Cor Ligthert" <no************@planet.nl> ha scritto nel messaggio
news:#O**************@TK2MSFTNGP14.phx.gbl...

I did nowhere write it is "better", when you see Hefried samples, than he is forever using Mid, Right, Left in that case I would find it very incosequent to use indexof.


:)

I don't care about bad-coded-samples ;)

--
Reporting tool: http://www.neodatatype.net
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.