View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default How to find multiple same char in a string in Excel?

On Tue, 9 Feb 2010 09:02:31 -0800 (PST), xhm wrote:

Hello:

I am trying to locate the last subdirectory name from a full path. For
example, I have a full path like:

"c:\temp\temp1\temp2"

I would like to find the temp2 which is the last subdirectory.

I am thinking to use find() to find the last "\", and then use left(),
right() or mid() to obtain it. The problem is, when I tried to use
find() function, it only returns the first position of the "\" in the
full path string. How can I get the last "\" position in the string?

p.s., I had searched the Internet, but all the examples I found were
just had one occurance of the char to be found, while in my case, I
have multiple same chars ("\") in the string.

Thanks for any help in advance.


Try:

=TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99))

which will return that last "\" separated substring from your string.
--ron