View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld
 
Posts: n/a
Default finding rightmost location of a character

On Mon, 23 Jan 2006 15:20:02 -0800, "KingGeezer"
wrote:

I have a text string (a directory path actually) that has several "/"
characters in it.
I'd like to find the location of the right-most occurrance of an "/".
For example, if the string was: "mama/poppa/bogus/dog" .... how do I find
the position number of the "/" right before 'dog'?
Thanks for any help you can provide!


You can use regular expressions to easily extract whatever phrase you wish from
the string.

They are available either via VBA, or, most easily, from Longre's free
morefunc.xll add-in at http://xcell05.free.fr

For example, to get the position of the last "/"

=REGEX.FIND(A1,"\/",-1)
or
=REGEX.FIND(A1,"\/\w+$")

But, perhaps you want the last word (dog):

=REGEX.MID(A1,"\w+$")

or perhaps everything except the last word:
mama/poppa/bogus/

=REGEX.MID(A1,".*\/")

Maybe without the trailing "/"
mama/poppa/bogus

=REGEX.MID(A1,".*(?=\/)")


--ron