Thread: Extract text
View Single Post
  #13   Report Post  
someone
 
Posts: n/a
Default

"Harlan Grove" wrote in message
ups.com...
someone wrote...
...
=LEFT(MID(x,SEARCH("S3",SUBSTITUTE(x,"S4","S3" )),1024),
FIND(".",MID(x,SEARCH("S3",SUBSTITUTE(x,"S4"," S3")),1024))-1)


Could I be so bold to ask ........ Could you explain it to me please ?


You're looking for only "S3" or "S4". This works because these two
strings are the same length.

The SUBSTITUTE call replaces "S4" with "S3" if there are any instances
of "S4" in x; otherwise, it leaves x as-is.

The SEARCH call then locates the leftmost instance of "S3" in the
string returned by SUBSTITUTE, so the leftmost character position of
"S3" or "S4" in the original x.

The MID call extracts the portion of x starting with the leftmost "S3"
or "S4" to the right end of x. The 1024 as 3rd argument to MID is a
dummy large number. MID won't return more characters than are in its
string 1st argument, so using an arbitrarily large 3rd argument ensures
MID returns the remaining substring to the right of its starting
position 2nd argument.

The FIND call locates the leftmost "." *after* the leftmost "S3" or
"S4".

The LEFT call returns the portion of the MID call's result to the left
of the leftmost "." following (to the right of) the leftmost "S3" or
"S4" in x.


Thank you so much for your help and efforts.

:-)