cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
marial16
Post Partisan
Post Partisan

get first 99 characters from string and concat

 Hallo,

i have an issue where the email subject in a flow must not be >100 characters.

so when an item is created i want to set the t\Title field in a variable .

then i use an expression which however returns a random string and not the first 99 characters concatenated with '...'

 

if(greater(length(variables('var_Title')),100),concat(substring(variables('var_Title'),99),'...'),variables('var_Title'))

 

The flow does not fail as before but i want the correct subject

Any ideas ?

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

The substring expression accepts three parameters:

  1. The string that you want to extract something from.
  2. The start position that you want to begin extraction.
  3. Optional length parameter.

Your expression:

 

if
(
  greater(length(variables('var_Title')),100),
  concat(substring(variables('var_Title'),99),'...'),
  variables('var_Title')
)

 

You are specifying only two parameters which means the substring is starting at position 99 and continuing until the end of the string, and then appending "...". You perhaps want it like this:

 

if
(
  greater(length(variables('var_Title')),100),
  concat(substring(variables('var_Title'),0,99),'...'),
  variables('var_Title')
)

 

But you also said the subject must not be more than 99 characters, 99+3 is 102, so perhaps you only want to capture the first 66 characters? Anyway, this should fix your issue.

 

View solution in original post

4 REPLIES 4
annajhaveri
Community Champion
Community Champion

@marial16 , the expression looks correct to get the first 99 characters and append '...' to it, what result does do you get out of it?

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

Instead of getting for example:

TextTexttexttextedfhdivbdsjhvdddvbd.....

 

i get the final  dddvbd..... characters.

i Apologize for the random data . i hope its clear

 

Paulie78
Super User
Super User

The substring expression accepts three parameters:

  1. The string that you want to extract something from.
  2. The start position that you want to begin extraction.
  3. Optional length parameter.

Your expression:

 

if
(
  greater(length(variables('var_Title')),100),
  concat(substring(variables('var_Title'),99),'...'),
  variables('var_Title')
)

 

You are specifying only two parameters which means the substring is starting at position 99 and continuing until the end of the string, and then appending "...". You perhaps want it like this:

 

if
(
  greater(length(variables('var_Title')),100),
  concat(substring(variables('var_Title'),0,99),'...'),
  variables('var_Title')
)

 

But you also said the subject must not be more than 99 characters, 99+3 is 102, so perhaps you only want to capture the first 66 characters? Anyway, this should fix your issue.

 

Looks like it solved the issue.

Thank you all

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (1,552)