Skip to main content
Dec 9, 2021 4:27 PM UTC
Solved

How can you use the 'toProperCase' function on a variable

Hi,

 

We would like to use the 'toProperCase' function on the <%= recipient.preferredName %> 

 

But unsure of how to format it? Please could someone help!

 

Thanks,

Tutu

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Manoj_Kumar
Manoj_KumarAccepted solution
Community Advisor
Dec 9, 2021 4:34 PM UTC

@tutsaa 

First define the function like this

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

Then you can use it like this 

<%= recipient.preferredName.toProperCase() %>

 

Manoj  | https://themartech.pro

3 replies

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
Dec 9, 2021 4:34 PM UTC

@tutsaa 

First define the function like this

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

Then you can use it like this 

<%= recipient.preferredName.toProperCase() %>

 

Translate
Manoj  | https://themartech.pro
David_Loyd
Adobe Employee
Adobe Employee
Dec 9, 2021 8:05 PM UTC

Could also do something like this... (The joy of JavaScript, 1000 ways to do the same thing!)

 

<%​
function nameProper() {​
  var name = recipient.firstName;​
  var propName = name.chartAt(0).toUpperCase() + name.slice(1);​
}%>​

Dear <%= nameProper %>,

 

​

Dear <%= nameProper %>,

Translate
Jyoti_Yadav
Level 8
Dec 10, 2021 6:40 AM UTC

Hi @tutsaa ,

 

You can use a simple version also:

<%= recipient.preferredName.substring(0,1).toUpperCase()+ recipient.preferredName.substring(1,100).toLowerCase() %>

 

Thanks,

Jyoti Yadav

Translate