Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!
SOLVED

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

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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
     Find me on LinkedIn

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

@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
     Find me on LinkedIn

Avatar

Employee Advisor

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 %>,

Avatar

Community Advisor

Hi @Tutsaa ,

 

You can use a simple version also:

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

 

Thanks,

Jyoti Yadav