Jump to content

This topic is 7824 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I have a text field witch is populated with the following text:

Macintosh HD:Users:Admin:Pictures:Adressbook:picture.jpg

Now I only want to extract the last word. In this case it would be "picture.jpg". The calculation would be rightwords(textfield,2). But the problem is that the file could have a compleet different filename.

Does somebody know how to search for the last ":" character and filter the filename out?

thnx & greetz,

Jeffer

Posted

whoop...found it myself:)

Right(textfield, (Length(textfield)-Position(textfield, ":", "0", PatternCount(textfield, ":"))))

greetz,

Jeffer

Posted

Jeffer,

The way you've found will work - but for the sake of interest, there are several other options also.

Provided your filenames don't include spaces or underscores (or other non alphanumeric characters apart from dots and dashes) you could use:

RightWords(textfield, 1)

- which will lift out picture.jpg or any other file name in that format. Note that it's a 1 not a 2 because the dot is not recognised as a word separator.

Alternatively, if you need to cater for underscores of spaces in the filenames, you could use:

Right(textfield, Length(RightWords(Substitute(Substitute(textfield, " ", "X"), "_", "X"), 1)

and, last but not least, along similar lines to the calc you arrived at, you could use:

Right(textfield, Length(textfield) - Position(textfield, ":", Length(textfield), -1))

wink.gif

Posted

Hi Ray,

Thanks for the reply...i like looking over some calculations again to really understand how they work:)

The first calc "RightWords(textfield, 1)" is a nasty one since you will never know what filename you're working with;)

The second one "Right(textfield, Length(RightWords(Substitute(Substitute(textfield, " ", "X"), "_", "X"))"

i don't really understand. Where do you need those "X" for?

greetz,

Jeffer

Posted

Hi Jeffer,

The use of Substitute is changing any spaces or underscores to 'X' before grabbing the rightmost word to check the length (which is then fed into the Right( ) function). This is because spaces and underscores are counted as word separators but can be included in field names, so changing them for an 'X' before testing for the length of the field name ensures that the whole name will be captured.

Cheers,

This topic is 7824 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.