Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Character Locations in Strings

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Character Locations in Strings

If you are specifically looking for three dots try

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

to get the position of the last dot.


"Pflugs" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Character Locations in Strings

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" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Character Locations in Strings

Tom,

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

Sincerely,
Matthew

"Tom Ogilvy" wrote:

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" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search group of cells for several sets of character strings Don Excel Discussion (Misc queries) 0 May 7th 09 11:36 PM
Date Formating and building character strings C Brandt Excel Discussion (Misc queries) 5 August 18th 07 03:39 AM
testing for character strings within a cell MKB Excel Worksheet Functions 2 August 29th 06 06:54 PM
Finding 13 character codes in text strings Bhupinder Rayat Excel Worksheet Functions 2 April 25th 06 05:14 PM
VB 255 character limit for strings Brett Excel Programming 7 January 11th 06 08:12 PM


All times are GMT +1. The time now is 11:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"