yvette
Cloud Wanderer

Capitalize only first letter of first word in complete string

Jump to solution

Hi all, 

 

In my workflow I need to capitalize the first letter of only the first word in a string. For example I want to convert "test test string" to "Test test string".

 

If I use the inline function fn-ToTitleCase it will capitalize every first letter of every word in the string.

 

How could I best go about doing this?

 

I am thinking about using a regular expression action. To either get all words based on the pattern \s and then loop through all the words, converting only the first word ToTitleCase and merge all words into a single string. Or maybe getting the first character of the string with a regex such as ^[a-z]{1}, then putting this character ToTitleCase, getting the substring and merging these again...

 

There must be an easier way! Thanks!

0 Kudos
Reply
1 Reply
MegaJerk
Automation Master
Automation Master

Re: Capitalize only first letter of first word in complete string

Jump to solution

You can do this with just a single String Builder for Single Line Text variables, or Two String Builders for Multiline Text variables. 

 

Example: 
image.png

I have two Starting Variables for my workflow. 

 

  1. input_String: is a Single Line Text
  2. input_Multi: is a Mutli Line Text

 

To process input_String, I have a Build String Action that is setup with the following inline functions: 

fn-ToUpper(fn-Substring(fn-Trim({TextStart}{WorkflowVariable:input_String}{TextEnd}),0,1))fn-Remove(fn-Trim({TextStart}{WorkflowVariable:input_String}{TextEnd}), 0,1)

 

image.png

 

 

To process the Multiline Text Variable, I have two (2) Build String Actions back to back. The first one will perform the Trim function and save over the original input: 

fn-Trim({TextStart}{WorkflowVariable:input_Multi}{TextEnd})

Notice that the output is going to the INPUT variable, overwriting it!!!Notice that the output is going to the INPUT variable, overwriting it!!!

 

 

And the second will do the rest of the heavy lifting: 

fn-ToUpper(fn-Substring({TextStart}{WorkflowVariable:input_Multi}{TextEnd},0,1))fn-Remove({TextStart}{WorkflowVariable:input_Multi}{TextEnd}, 0,1)

image.png

 

This produces the following results: 

input_String = hello world

output_String = Hello world


input_Multi = lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce faucibus orci ipsum, id sollicitudin ipsum efficitur sit amet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque nec vehicula nisi. Ut sodales sem eget mi vehicula blandit. Aliquam nec augue at dui dictum interdum vel sagittis ipsum. Vivamus at neque mauris. Aliquam sit amet faucibus lectus. Donec sit amet massa tincidunt, consequat est scelerisque, aliquam ipsum. Ut dui quam, porttitor a porttitor et, eleifend eu lorem.

In rutrum diam eget sapien hendrerit efficitur. In pellentesque dignissim sagittis. Proin justo sapien, malesuada at dolor ac, malesuada sollicitudin ex. Nunc diam nisi, aliquet vitae quam at, accumsan sodales orci. Nam mattis dictum mauris, eget viverra quam tincidunt a. In ullamcorper, lectus sed bibendum condimentum, sapien sem commodo turpis, sed ullamcorper leo ex a risus. Proin ante urna, imperdiet eget justo interdum, hendrerit lacinia massa. Pellentesque porttitor faucibus sagittis. Fusce mattis euismod dolor ac consequat.

output_Multi = Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce faucibus orci ipsum, id sollicitudin ipsum efficitur sit amet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque nec vehicula nisi. Ut sodales sem eget mi vehicula blandit. Aliquam nec augue at dui dictum interdum vel sagittis ipsum. Vivamus at neque mauris. Aliquam sit amet faucibus lectus. Donec sit amet massa tincidunt, consequat est scelerisque, aliquam ipsum. Ut dui quam, porttitor a porttitor et, eleifend eu lorem.

In rutrum diam eget sapien hendrerit efficitur. In pellentesque dignissim sagittis. Proin justo sapien, malesuada at dolor ac, malesuada sollicitudin ex. Nunc diam nisi, aliquet vitae quam at, accumsan sodales orci. Nam mattis dictum mauris, eget viverra quam tincidunt a. In ullamcorper, lectus sed bibendum condimentum, sapien sem commodo turpis, sed ullamcorper leo ex a risus. Proin ante urna, imperdiet eget justo interdum, hendrerit lacinia massa. Pellentesque porttitor faucibus sagittis. Fusce mattis euismod dolor ac consequat.

As you can see, we have only changed the first letter of the first word in both cases. 

I'm not entirely sure why multiline text breaks the inline functions with proper {TextStart} and {TextEnds}, but I sadly could not get the Multiline Text to process fully in a single Action no matter how I changed things around. If someone knows why that is and can fix it up even more, please do chime in! 

I hope this helps to solve your problem!

View solution in original post

0 Kudos
Reply