Emma in England Posted September 19, 2005 Posted September 19, 2005 I need to create a field which looks at an existing field and strips out everything in it which is between chevrons, i.e. replace with nothing. How do I put this into the function? I've tried asterisks and it doesn't understand them, I guess because in a function they mean multiplication! First post, hope someone can help! Emma
SlimJim Posted September 19, 2005 Posted September 19, 2005 Moderately straightforward if there is only one pair of chevrons - call the fields Stripped and Chevrons Stripped = Left (Chevrons, Max(Position(Chevrons,"<",1,1)-1,0)) & Right(Chevrons,Length(Chevrons) - Position(Chevrons;">",1,1))) The max takes account of no chevrons. If there is a possibility of more than one unspecified number of chevrons then I think you need a recursive or looping method. That is treat the above as an intermediate calculation and keep doing it until there are no chevrons left. By the way - I am using version 8. I think the formula is OK for version 5.
Emma in England Posted September 19, 2005 Author Posted September 19, 2005 There could be as many as 20 chevroned tags in the source field (it's linked to a QuarkXPress document and the tags are Quark styles). Your solution doesn't work for me in v5 - the Max function requires a field name only as a parameter. I'm working on adapting it (leaving out the Max seems to help!) just to isolate a couple of chevrons but it seems very complicated. Is it really not possible to just put in a wildcard?:)
onthebass Posted September 19, 2005 Posted September 19, 2005 Slim Jim, I haven't used the Max function much, if ever. How does it function here? Emma, Wildcard "*" is used in searching, not in calculations. If you have 20 chevrons and you don't want to use a script you could use a series of calcs. You just have to be sure to account for the maximum possible occurrences of Chevrons. Stripped1 = Left (Chevrons, Position(Chevrons,"<",1,1)-1,0)) & Right(Chevrons,Length(Chevrons) - Position(Chevrons;">",1,1))) Stripped2 = Left (Stripped1, Position(Stripped1,"<",1,1)-1,0)) & Right(Stripped1,Length(Stripped1) - Position(Stripped1;">",1,1))) Stripped3 = Left (Stripped2, Position(Stripped2,"<",1,1)-1,0)) & Right(Stripped2,Length(Stripped2) - Position(Stripped2;">",1,1))) Stripped4 = Left (Stripped3, Position(Stripped3,"<",1,1)-1,0)) & Right(Stripped3,Length(Stripped3) - Position(Stripped3;">",1,1))) etc.... This might be excessive for more than one field you want to strip, but for one field that you are going to use a frequently and want it to refresh on the fly instead of having to run a script it's not so bad.
SlimJim Posted September 19, 2005 Posted September 19, 2005 Slim Jim, I haven't used the Max function much, if ever. How does it function here? Here I am calculating using the Position function which can return a value of 0 and then subtracting 1 will produce a negative value in the number of characters for the Left function. I have no idea how the Left function will react to a negative number of characters so taking Max(...;0) will produce a 0 whenever the Position is 0. Someone on these forums (I think it was comment) pointed out that you can use constants within a Max even though the Filemaker help file explicitly states that the arguments of the Max should be any related field, repeating field, or set of non-repeating fields; or an expression that returns a field, repeating field, or set of non-repeating fields.
SlimJim Posted September 19, 2005 Posted September 19, 2005 (edited) Just for the record: I went back to FMP version 3 and the Max function works in the same way, i.e, you can Max a field and a constant value, e.g. Max(field,10) will return the larger of 10 and the value of field. But, it will not accept an expression instead of a field. Edited September 19, 2005 by Guest
SlimJim Posted September 20, 2005 Posted September 20, 2005 To get back to Emma's original question. I think a scripted solution is the answer. I have tested this in version 3 so it should be OK. Name the text field that receives the input as Field1 and the intended output field as Field2 add in an extra field Field3 for use in the script. (Field3 can be golbal text) Use the following script Set Field["Field2,"Field1] Loop Exit loop if ["Position(Field2,"<",1,1) = 0"] Set Field["Field3","Left(Field2, Position(Field2,"<",1,1)-1)& Right(Field2,Length(Field2) - Position(Field2,">",1,1))" Set Field("Field2","Field3") End Loop This script loops through the field removing pairs of chevrons and the text between them until there are no more "<" left to remove. If you want this to run through all the records then add Find All Go to Record/Request/Page[first] Loop on the front of the script and Go to Record/Request/Page[Exit after last, Next] End Loop on the end of the script.
bruceR Posted September 20, 2005 Posted September 20, 2005 You need a custom function, not a script. Look at the field substitute custom function in the custom function section of this forum. It does EXACTLY what you're looking for.
-Queue- Posted September 20, 2005 Posted September 20, 2005 This would only be helpful if you could make a Custom Function work in FM 5. :wink2:
Recommended Posts
This topic is 7102 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