Feature Request: A new string operator – Trunc

In the Wikipedia pack I find it’s pulling a lot of text into the Body field making tables very long (and documents very big). I don’t see a way to limit the amount of text that is pulled in by the pack, which is what I want.

A generalized “Trunc” string operator that could be used in any formula where it would be appropriate might be useful in other contexts (Gmail pack?), but my request is that “Trunc” gets added by default to the formula in the body field of the Wikipedia pack.

The formula syntax may be wrong (I am new here) but here’s my thoughts:

“trunc.donot {}” // no truncation, default case
“trunc.chars {42}” // truncs after 42 characters
“trunc.words {10}” // truncs after 10 words
“trunc.paras {1}” // truncs after one paragraph :: my preferred usage
“trunc.delim {#8212}” // truncs after the first em dash

Perhaps the trim function should be called in the background before and after to remove unwanted spaces if it is not already.

2 Likes

@Clay_Gordon I think you can accomplish this with either Left() or by using Split(). You could split on a space for words or char(10) for paragraphs. Not as elegant but might get you there.

I don’t see how that would work. I don’t see how to add a numeric count and it looks like the function replaces the specified delimiter (and what would I enter for paragraph … \r?) with a comma followed by a space.

But specifically in the case that prompted my request … I cannot edit the formulas in the Wikipedia pack.

I may be able to create a view of the Wikipedia table and apply the formula to the referenced column but that would mean duplicating the table and increasing the size of the document – so not what I am looking for, ultimately. But thank you for the thought.

If you want the first 100 characters of the post bring it in its entirety and then use Left(100) to bring that in?

1 Like

That does get me the first “N” chars, but I still can’t edit the formula in the Wikepedia pack.

However, if the Wikipedia pack were updated to include this capability and I could specify the number of characters that would be a great start.

It also makes sense (to me) to have a more general function that works on more than character count. This would require the Left function to be updated to recognize a special case argument (such as 0) that would mean pull in the entire string.

Left(“Hello world”, 0)

That’s one reason why I creating a separate Trunc function makes sense. I think extracting the first 0 characters of a string is an ugly cheat for do nothing to the string.

Hi @Clay_Gordon,
I’m not sure I really understood your issue :thinking:

but I fully agree with @Johg_Ananda.

Please, have a look at this simple implementation:

and tell me if this is close to your desired output.
1 Like

Federico - Thank you for taking a look at this for me. I am a newbie to Coda, evaluating moving a large project from Airtable. I am attracted to the richness of the programming environment but I am still working my way around the language. I realize there are lots of ways to achieve similar results.

When I said I could not edit the column formulas in the Wikipedia it as because of my lack of understanding of the platform.

What I want to do is reduce the row height. I don’t think this is possible by reference because your formula

thisRow.Article.Left(thisRow.[Chars Count])

works on the article body after the text has been imported. Hiding the column does not change the row height.

What I want to do is change this:

Wikipedia::Article(thisRow.Title).Body

so I only pull in and display a specified number of characters or paragraphs in the article body cell.

@Clay_Gordon give this a try:

left(Wikipedia::Article(thisRow.Title).Body,100)

Of course adjust 100 to whatever you want. Best practice would be to create a global variable/formula for the character value.

So, I tried it myself for and the following works:

left(thisRow.[Article Name].Body, 200)

I just change the “200” to any char count I want. The next step is to add an ellipsis character to the end to indicate it’s a snippet.

@Clay_Gordon Yep you’re getting it:

concatenate(left(thisRow.[Article Name].Body, 200),"...")

Yep. Thanks!

I was noodling around and came up with this solution:

Concatenate(left(thisRow.[Article Name].Body,144), " …")

after a little bit of trial and error. I am trained as a photographer, not a programmer, and my last real coding work was well over a decade ago so I am rusty. I don’t need to generalize this into a variable as it’s a one-time use of the Wikipedia pack in my document.

2 Likes