jeffer Posted August 28, 2003 Posted August 28, 2003 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
jeffer Posted August 28, 2003 Author Posted August 28, 2003 whoop...found it myself:) Right(textfield, (Length(textfield)-Position(textfield, ":", "0", PatternCount(textfield, ":")))) greetz, Jeffer
CobaltSky Posted August 28, 2003 Posted August 28, 2003 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))
jeffer Posted September 1, 2003 Author Posted September 1, 2003 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
CobaltSky Posted September 1, 2003 Posted September 1, 2003 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,
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now