Select to view content in your preferred language

Longest string of ALL cells of a table.

5583
14
08-26-2014 01:52 PM
AlexZhuk
Frequent Contributor

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?

0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   What context are you asking this question in? Are you talking about a certain API, desktop, or what?

0 Kudos
AlexZhuk
Frequent Contributor

Robert,

this is for the labeling expression in Desktop. Thanks!

0 Kudos
DanPatterson_Retired
MVP Emeritus

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?

0 Kudos
AlexZhuk
Frequent Contributor

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.

0 Kudos
curtvprice
MVP Esteemed Contributor

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.

0 Kudos
AlexZhuk
Frequent Contributor

I have something already , unfortunately, the separate parts of it work, but together they don"t

Function.png

0 Kudos
AlexZhuk
Frequent Contributor

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.

exmp.png

0 Kudos
IanMurray
Honored Contributor

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.

0 Kudos
AlexZhuk
Frequent Contributor

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.

0 Kudos