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

string.indexOf and "%s"

P: n/a
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?


Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
ahum :-)

Dim s As String
Dim i As Integer

s = "hello %s"

i = s.IndexOf("%s")

MsgBox(i)

well ,,,, do i need to say more :-) ???
Michel Posseth [MCP]
"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?

Nov 21 '05 #2

P: n/a
you could also use VB`s instr() function

wich is maybe more clear in what it does
like this
Dim s As String

Dim i As Integer

s = "hello %s"

i = InStr(s, "%s")


"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?

Nov 21 '05 #3

P: n/a
Aargh, in my contrivance to make it a simple example I buggered it up.

Try this...
s = "hello %s"

s = "%s|%s|%s"

i = s.IndexOf("%s")

MsgBox(i)

The "hello %s" works. the other one doesn't. I know I could fall back to
instr() but I am trying to stay in the spirit of things.

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:42***********************@nova.planet.nl...
ahum :-)

Dim s As String
Dim i As Integer

s = "hello %s"

i = s.IndexOf("%s")

MsgBox(i)

well ,,,, do i need to say more :-) ???
Michel Posseth [MCP]
"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?


Nov 21 '05 #4

P: n/a
well i don`t see anything wrong
Dim s As String

Dim i As Integer

s = "%s|%s|%s"

i = s.IndexOf("%s")

MsgBox(i)

gives a result of 0 wich is correct

chars %s|%s|%s = index 01234567

The indexOf method returns an integer value indicating the beginning of the
substring within the String object. If the substring is not found, a -1 is
returned.

so ,,,, :-) ,,,,,,

happy coding

Michel Posseth [MCP]


"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Aargh, in my contrivance to make it a simple example I buggered it up.

Try this...
s = "hello %s"

s = "%s|%s|%s"

i = s.IndexOf("%s")

MsgBox(i)

The "hello %s" works. the other one doesn't. I know I could fall back to
instr() but I am trying to stay in the spirit of things.

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:42***********************@nova.planet.nl...
ahum :-)

Dim s As String
Dim i As Integer

s = "hello %s"

i = s.IndexOf("%s")

MsgBox(i)

well ,,,, do i need to say more :-) ???
Michel Posseth [MCP]
"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring
like "%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?



Nov 21 '05 #5

P: n/a
Hi,

Remember that 0 is the first position of the string.

Ken
-------------------
"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?

Nov 21 '05 #6

P: n/a
Ah ha. The man has an answer. I guess I am thinking instr(). who would of
thunk they'd be different...

thanks.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
Hi,

Remember that 0 is the first position of the string.

Ken
-------------------
"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
for some reason I can get a string.index of to recognize a substring like
"%s".

dim s as string
dim i as integer
s = "hello %s"
i = s.indexof(s)

'--- i is zero

what gives?


Nov 21 '05 #7

P: n/a
Jeff,

That is the only reason I don't use those parts of the microsoft.visualbasic
namespace. Altough better, does the starting of the indexers with First
confuse me.

I use only classes (functions) that use start of the indexer with Zero.
(Although I find that one of the worst thing from high level languages
except VB that they never tried to bring that to human standards)

In my language there is no seperate word for it. You say it starts with
(met) "Nul" what is the same as start with nothing.

If you ask yourself why I write this, it is a nice place to give my opinion
although you can maybe do nothing with it.

:-))

Cor
Nov 21 '05 #8

P: n/a
> I use only classes (functions) that use start of the indexer with Zero.
(Although I find that one of the worst thing from high level languages
except VB that they never tried to bring that to human standards)


I think of it like this:-

If the first element of an entity is referred to as the zeroth entity, then
it is using an offset.
If the first element of an entity is referred to as the first entity, then
it is using an index.

Unfortunately, the rest of the world does not refer to it that way.

Andrew
Nov 21 '05 #9

P: n/a
while i have tinkered with .net on my own, my work is just now looking to
move to it. i am working to not use the old vb names and am very much
trying to do things the .net way, but my mind still thinks the old way.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e0**************@TK2MSFTNGP14.phx.gbl...
Jeff,

That is the only reason I don't use those parts of the
microsoft.visualbasic namespace. Altough better, does the starting of the
indexers with First confuse me.

I use only classes (functions) that use start of the indexer with Zero.
(Although I find that one of the worst thing from high level languages
except VB that they never tried to bring that to human standards)

In my language there is no seperate word for it. You say it starts with
(met) "Nul" what is the same as start with nothing.

If you ask yourself why I write this, it is a nice place to give my
opinion although you can maybe do nothing with it.

:-))

Cor

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.