Character Locations in Strings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I access specific character locations within strings? I know in C++
you can access them using brackets (i.e. string[1]), but I can't figure it
out for VB.

To illustrate, for the example string "...Clamp 0.2", I am trying to find
the position of the last period in a series of periods. I tried using
"InStrRev," but that gave me a false positive by reporting the period in
"0.2". The series of periods designates a level within a tree structure, so
its position is very important. Is there any way I can use "InStr" or
"StrComp" or something with this. I need it to be very fast as there are
35,000 lines to process.

Thanks,
Pflugs
 
If you are specifically looking for three dots try

iPos = InStr("...Clamp 0.2", "...") + 2

to get the position of the last dot.
 
Assume the periods are always at the start

ipos = instr(1,activecell,Left(Replace(Activecell,".",""),1),vbTextCompare)
- 1

demo'd in the immediate window:
ActiveCell.Value = "...Clamp 0.2"
ipos = instr(1,activecell,Left(Replace(Activecell,".",""),1),vbTextCompare)
- 1
? ipos
3
 
Tom,

As always, thanks for your quick and helpful advice. I appreciate it.

Sincerely,
Matthew

Tom Ogilvy said:
Assume the periods are always at the start

ipos = instr(1,activecell,Left(Replace(Activecell,".",""),1),vbTextCompare)
- 1

demo'd in the immediate window:
ActiveCell.Value = "...Clamp 0.2"
ipos = instr(1,activecell,Left(Replace(Activecell,".",""),1),vbTextCompare)
- 1
? ipos
3

--
Regards,
Tom Ogilvy



Pflugs said:
How do I access specific character locations within strings? I know in C++
you can access them using brackets (i.e. string[1]), but I can't figure it
out for VB.

To illustrate, for the example string "...Clamp 0.2", I am trying to find
the position of the last period in a series of periods. I tried using
"InStrRev," but that gave me a false positive by reporting the period in
"0.2". The series of periods designates a level within a tree structure, so
its position is very important. Is there any way I can use "InStr" or
"StrComp" or something with this. I need it to be very fast as there are
35,000 lines to process.

Thanks,
Pflugs
 

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