Hi Chris! I see where you also posted this question here. Just want to keep this connected in case other community members run across this thread. Hopefully you will trigger the Javascript experts to assist you
var str = "user546"; var capFirst = str.substring(0,1).toUpperCase() + str.substring(1,str.length);
Walking through the code:
"str" holds your original string
.substring(0,1) gives you the first character of the string
.toUppercase() converts the given string to uppercase
.length gives you the length of the string
.substring(1,str.length) gives you everything after the first character
so the second statement takes the first character of str and converts it to UpperCase and then concatenates (+) that with the rest of the string (after the first character).
Using this code, capFirst will hold the string "User546"
I had actually just been tinkering and came up with this
var player = GetPlayer(); var myName = lmsAPI.GetStudentName(); var array = myName.split(','); var str = array[1]; var newName = str.slice(0,1).toUpperCase() + str.slice(1); player.SetVar("newName", newName);
Slightly different approach, but simialr outcome, so now others can choose from both!
Learners first and last name are all caps in our LMS. I've been trying to come up with a code to correct students first and last names to title case. Here is the code that we are currently using:
var lmsAPI = parent
var rawName = lmsAPI.GetStudentName();
var nameArray = rawName.split(",")
var niceName = nameArray[1] +" "+nameArray[0];
var p = GetPlayer();
p.SetVar("username",niceName);
Does anyone knows the code to correct the full name to tile case?
function initCap(strIn){ var allChars = strIn.split(""); // convert string to array of characters var strOut = allChars[0].toUpperCase(); // initial character (ndex=0), force upper case
for(var i=1; i strOut += allChars[i].toLowerCase(); // concatenate the lower case version or remaining } return strOut; }
and replace your line like this:
var niceName = initCap(nameArray[1]) + " " + initCap(nameArray[0]);
8 Replies
Hi Chris! I see where you also posted this question here. Just want to keep this connected in case other community members run across this thread. Hopefully you will trigger the Javascript experts to assist you
Here's some Javascript for you to try:
var str = "user546";
var capFirst = str.substring(0,1).toUpperCase() + str.substring(1,str.length);
Walking through the code:
"str" holds your original string
.substring(0,1) gives you the first character of the string
.toUppercase() converts the given string to uppercase
.length gives you the length of the string
.substring(1,str.length) gives you everything after the first character
so the second statement takes the first character of str and converts it to UpperCase and then concatenates (+) that with the rest of the string (after the first character).
Using this code, capFirst will hold the string "User546"
Good luck,
Paul K.
Awesome! Thanks Paul for popping in to help Chris out here.
Thanks Paul, much appreciated.
I had actually just been tinkering and came up with this
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var str = array[1];
var newName = str.slice(0,1).toUpperCase() + str.slice(1);
player.SetVar("newName", newName);
Slightly different approach, but simialr outcome, so now others can choose from both!
Result all round
Thanks again
Awesome! Thanks for sharing Chris
Hi,
Learners first and last name are all caps in our LMS. I've been trying to come up with a code to correct students first and last names to title case. Here is the code that we are currently using:
var lmsAPI = parent
var rawName = lmsAPI.GetStudentName();
var nameArray = rawName.split(",")
var niceName = nameArray[1] +" "+nameArray[0];
var p = GetPlayer();
p.SetVar("username",niceName);
Does anyone knows the code to correct the full name to tile case?
Any help would be appreciated!
Try adding this function:
function initCap(strIn){
var allChars = strIn.split(""); // convert string to array of characters
var strOut = allChars[0].toUpperCase(); // initial character (ndex=0), force upper case
for(var i=1; i
strOut += allChars[i].toLowerCase(); // concatenate the lower case version or remaining
}
return strOut;
}
and replace your line like this:
var niceName = initCap(nameArray[1]) + " " + initCap(nameArray[0]);
Good luck,
Paul K.
Thanks Paul! I modified the code and added the function, unfortunately it's not working.
This discussion is closed. You can start a new discussion or contact Articulate Support.