Excel: last character/string match in a string -


is there efficient way identify last character/string match in string using base functions? i.e. not last character/string of string, position of character/string's last occurrence in string. search , find both work left-to-right can't think how apply without lengthy recursive algorithm. , this solution seems obsolete.

i think mean. let's example want right-most \ in following string (which stored in cell a1):

drive:\folder\subfolder\filename.ext

to position of last \, use formula:

=find("@",substitute(a1,"\","@",(len(a1)-len(substitute(a1,"\","")))/len("\"))) 

that tells right-most \ @ character 24. looking "@" , substituting last "\" "@". determines last 1 using

(len(string)-len(substitute(string, substring, "")))\len(substring) 

in scenario, substring "\" has length of 1, leave off division @ end , use:

=find("@",substitute(a1,"\","@",len(a1)-len(substitute(a1,"\","")))) 

now can use folder path:

=left(a1,find("@",substitute(a1,"\","@",len(a1)-len(substitute(a1,"\",""))))) 

here's folder path without trailing \

=left(a1,find("@",substitute(a1,"\","@",len(a1)-len(substitute(a1,"\",""))))-1) 

and filename:

=mid(a1,find("@",substitute(a1,"\","@",len(a1)-len(substitute(a1,"\",""))))+1,len(a1)) 

however, here alternate version of getting right of last instance of specific character. using our same example, return file name:

=trim(right(substitute(a1,"\",rept(" ",len(a1))),len(a1))) 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -