Count Number of Lines (Carriage Returns) in a String

I need to be able to count the number of $lf or carriage returns in a long string. I am attempting to apply visual formatting to scale the font size down when a note field has more than a certain number of lines. The lines are added by the customer service department as they insert carriage returns in the note field to organize longer notes. The below screenshot is an example. I have tried many combinations of different functions to try and isolate the carriage return characters so that I could count the number of lines, but without any success. Is this possible in Docentric?

Hi @AOCUSA_Baaron ,

You can achieve it by using the combination of string-length() and translate() functions. The approach is to compare lengths of the original field value and field value without the characters in question. The example would look like this:

string-length(SalesInvoiceHeader/@BuyerAddress) - string-length(translate(SalesInvoiceHeader/@BuyerAddress, $lf, ''))

Thank you Semir, that worked. I appreciate the quick reply. I was able to create a scaling font size for that note field, depending on the number of lines, using the below statement.

iif(string-length(SOInv/@Notes) - string-length(translate(SOInv/@Notes, $lf, ‘’))
< 6,9,
iif(string-length(SOInv/@Notes) - string-length(translate(SOInv/@Notes, $lf, ‘’))
< 11,8,
iif(string-length(SOInv/@Notes) - string-length(translate(SOInv/@Notes, $lf, ‘’))
< 16,7,6)))

1 Like

Great to hear that it works @AOCUSA_Baaron!