string.indexOf and "%s"

  • Thread starter Thread starter Jeff Jarrell
  • Start date Start date
J

Jeff Jarrell

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?
 
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]
 
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")
 
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 said:
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 said:
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?
 
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 said:
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 said:
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 said:
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?
 
Hi,

Remember that 0 is the first position of the string.

Ken
-------------------
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?
 
Ah ha. The man has an answer. I guess I am thinking instr(). who would of
thunk they'd be different...

thanks.
 
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
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top