I need to find the longest string of ALL cells of a table. Unfortunately, the table can have varying number of fields each time. Is it doable?
Alex,
What context are you asking this question in? Are you talking about a certain API, desktop, or what?
Robert,
this is for the labeling expression in Desktop. Thanks!
Yes...but how to you intend to implement it? It also seems like a lot of work to read every record in every field in a table looking for the longest. Can you provide some context as to why this is needed?
it is going to be a "sub" function for the FindLabel function. I need it for calculating a number of empty spaces in a label, which depends on the max number of characters, etc. It's all to make multi-row labels nicely justified, regardless of varying nature of data that go into labels. Thanks.
The label expression itself can only "see" the one row of the table being used to label each feature.
Note that length is only defined for strings, for non-string fields you'd have to convert to text (using some formatting rule) before you could calculate a length. This could be done using a Python script.
Can you explain what you're trying to do? That may help us answer your question with little more intelligence.
I have something already , unfortunately, the separate parts of it work, but together they don"t
function(*argums) allows for varying list of arguments to be accepted.
the frame part inspects the function's "input". These things work fine separately.
Here, however, the for loop completely ignores the frame.
I need this as a generic solution for the labels like shown here. Currently I need to calculate the longest strings manually.
Hey you looked at python's string formatting using their center, left justify, and right justify? You can set the number of of characters a string needs to be then it autofills the remaining spaces in a string with spaces to the specified number. If you determine the max string length prior, you can just input the width in the string method and (hopefully) it would work for you.
string.ljust for left justified
string.rjust for right justified
string.center for centered.
7.1. string — Common string operations — Python v2.7.8 documentation very bottom of the page.
Ian,
Thanks, I'll take a look at your links. Basically this is what I've been trying to do. My label data rows consist of a combination of, at least, two field values. I'm trying to calculate the max length of the box (fixed-width font is important here) and fill in all the empty spaces with respective number of space characters.