Truncating a string

187 views
Skip to first unread message

ellen....@gmail.com

unread,
Oct 3, 2008, 5:29:19 PM10/3/08
to XMPie Interest Group
What's the most efficient way to do the following:

I need to truncate the file extension from a field in a data file.
However, the number of characters before the period is variable, so I
can't do the usual thing and count forward to the point where I want
the string to end. How would I use the Length function to step
backward from the end four spaces (I need to cut off ".pdf" from every
field)?

Thanks!

Alan Dixon

unread,
Oct 4, 2008, 2:34:10 AM10/4/08
to xmpie...@googlegroups.com
You can use a conditional rule to find the length

If length = 10
Then you need a substring of 6
Else if length = 11
You will need to extend the substring length to 7
Etc

Obviously the above is theory not the Qlingo as you need to incorporate the field into the rule.


Regards Alan

Technical Director - Positive Focus
Sent from my BlackBerry® wireless device

Alan Dixon

unread,
Oct 4, 2008, 2:53:55 AM10/4/08
to xmpie...@googlegroups.com
I don't know if you could also try the right trim function. Normally it simply removes spaces, but there may be an option to Rtrim 4 characters. It may be worth a try and a simpler rule than the condional rule where you will have to write ev ryhting that will incorporate the shortest to longest options.

Louis

unread,
Oct 3, 2008, 8:18:27 PM10/3/08
to XMPie Interest Group
i've uploaded a sample with an excel file, a plan and a proof set (to
show the output) onto the files section. its called xmpie.zip.
hope it helps.

On Oct 3, 11:29 pm, "ellen.heit...@gmail.com"

Louis

unread,
Oct 3, 2008, 8:01:38 PM10/3/08
to XMPie Interest Group
Is this within uPlan?
If so, you could use the Replace(exprAsString, exprAsString,
exprAsString, exprAsString) function and just replace ".pdf" with a ""
whereever it appears? Havent tried it, but if it works like the Excel
"substitute()" function than we may have a winner....


On Oct 3, 11:29 pm, "ellen.heit...@gmail.com"
<ellen.heit...@gmail.com> wrote:

Louis

unread,
Oct 3, 2008, 8:15:54 PM10/3/08
to XMPie Interest Group
here's the expression you want...
FindAndReplace(|->[VarName], ".pdf", "")
where VarName is the string that contains the .PDF text you want to
remove. this will work regardless of where in the string the .pdf
appears because it doesn't need to be told where to start looking
(like replace)

On Oct 3, 11:29 pm, "ellen.heit...@gmail.com"
<ellen.heit...@gmail.com> wrote:

Bill

unread,
Oct 4, 2008, 4:49:23 AM10/4/08
to XMPie Interest Group
If you have a uDirect Premier or PersonalEffect configuration, a uPlan-
made Javascript custom function should help (in this sample, the
function is named RemoveFileExtension, its parameter named
MyFileName):
___________

for (var CharIdx = MyFileName.length ; CharIdx>0 ; CharIdx--)
if (MyFileName.substr(CharIdx, 1)==".")
return(MyFileName.substr(0, CharIdx)) ;
return MyFileName ;
___________

The ADOR rule should look like this:
___________
RemoveFileExtension(|->[MyWholeFileName])
___________
Reply all
Reply to author
Forward
0 new messages