August 28, 200322 yr 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
August 28, 200322 yr Author whoop...found it myself:) Right(textfield, (Length(textfield)-Position(textfield, ":", "0", PatternCount(textfield, ":")))) greetz, Jeffer
August 28, 200322 yr 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))
September 1, 200322 yr Author 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
September 1, 200322 yr 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,
Create an account or sign in to comment