Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
haymarketpaul
Creator III
Creator III

Extract A Sentence Without The Last Word

I should probably know how to do this but my brain's gone numb.

I need all but the last word of a sentence.

For example if i have a sentence...

This is a sentence then i need just the This is a part

So the sentence could have any number of spaces in it and i just need to lose the last word of it

Example2

Here is a slightly longer sentence would leave me with Here is a slightly longer

Thanks for help

1 Solution

Accepted Solutions
dplr-rn
Partner - Master III
Partner - Master III

try

Left('Here is a slightly longer sentence',Index('Here is a slightly longer sentence', ' ', -1)-1)

View solution in original post

4 Replies
antose
Partner - Creator II
Partner - Creator II

Hi!

Try Subfield('This is a sentence', Subfield('This is a sentence', ' ',-1), 1)

dplr-rn
Partner - Master III
Partner - Master III

try

Left('Here is a slightly longer sentence',Index('Here is a slightly longer sentence', ' ', -1)-1)

haymarketpaul
Creator III
Creator III
Author

Thanks Both for the replies

For reasons I can't accurately explain Anders solution didn't quite work for all scenarios but Dilip's was fine.

eg

One of my sentences said the following

aecom and pelli clarke pelli

Anders solution produced:   aecom and

whilst Dilip's produced:        aecom and pelli clarke

There seem to be a few that seem to be like that.

Anyway interesting and many thanks

swuehl
MVP
MVP

Anders solution is retrieving the last word using the second subfield() and uses this as separator for the first subfield.

This should work as long as the last word does not repeat in the sentence (like pelli occurs twice in your sample).

Hence better use Dilip's solution which relies only on space as separator, which is the separator in your original requirement.