Jump to content
Salesforce and other SMB Solutions are coming soon. ×

copy last word from field


Recommended Posts

I need a script that will take the last word or value from one field and move that 1 word or value to another field by itself. I need it to take that last word or value regardless if its 2 words in the field or 3 paragraphs, all I want is the last word or value.


I've tried "RightWords" and "RightValues" but depending on the amount of text that the field contains, I dont always get the result that I want.


The reason I need it to be the last word OR value is because it could be any of the following...










here is a bunch of text andrew.nicolay




here is a bunch of text


and here is some more andrew.nicolay




Any help would be great,


Link to comment
Share on other sites

Ok, well I just eliminated about 90% of the records that I needed to process by just creating a word count field and then finding all of the fields that only contain 1 word and then moving that 1 word... but now I sill have everything that contains more than one paragraph or word/value "word.nextword"

Link to comment
Share on other sites

Your Set Variable or Set field or calc field or whatever you are using could look like this:


Let ([


Field = Blah::TheField ;

SpaceCount = PatternCount ( Field ; " " ) ;

DotCount = PatternCount ( Field ; "." ) ;

LastSpacePos = Position ( Field ; " " ; 1 ; SpaceCount ) ;

LastDotPos = Position ( Field ; "." ; 1 ; DotCount ) ;

StartingPos = if ( LastSpacePos > LastDotPos ; LastSpacePos ; LastDotPos ) ;


LastWord = Right ( Field ; Length ( Field ) - StartingPos )











Okay, so what is it doing. First we count the number of space " " characters in the block of text, then we count the number of dots. Using this, we obtain in the field the position of the very last space and the very last dot (if there are neither the result will be 0)


We want to take everything after either the last space or the last dot, So we check the positions of each and we take the one which appears closer to the end of the block of text (whichever one has the highest position in the text).


Using this, we want to then simply take everything between this starting position, and the end of the text, to do this we take the # of characters required (Length of text - StartingPos )


Hopefully this will work out for you. It currently only assumes you take a word to be everything preceeded by a space or a dot.


There may be conditions that arise where this might fail such as the very last character in the field being a space or a dot, in this case , in the above calculation change


Field = Blah::TheField ;




Field = Trim ( Blah::TheField ) ;



If the last character is a dot you'll need to get more fancy and check this condition earlier, if the last character is a dot, use the second to last etc... I'll leave this bit up to you because it may never arise.

Link to comment
Share on other sites

After posting my response then re-reading your post I don't think I quite got the requirements right, you say last word OR value? Does that mean:


If the block of text is only 1 line - take the last word

If the block of text is multiple lines - take the last line?


Can you be a bit more clear?


Also, ignore my first post lol I came up with a far more simplistic way to achieve what I was trying to (that being the last word)



RightWords ( Substitute ( Text ; "." ; " " ) ; 1 )



A bit easier lol.



If my above assumption is correct then try this:



Let (


Values = ValueCount ( Text ) ;


if ( Values > 1 ; GetValue ( Text ; Values ) ; RightWords ( Substitute ( Text ; "." ; " " ) ; 1 )






Hopefully one of these calcs resembles what you want :)

Link to comment
Share on other sites

This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use