- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 05:37 AM
Hi all,
I have a requirement where i get values from excel sheet and using transform map i have to load it in servicenow. Can anyone please let me know how to convert all the capitals coming to smaller case except the first letter along with spaces. Please find below the format:'
For example:
ABCD EFGH IJKL
I want the output to look like below:
Abcd Efgh Ijkl
Kindly suggest me on this.
Thanks,
Neha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 06:03 AM
Try this:
var str = 'this is a test';
var pieces = str.split(" ");
for ( var i = 0; i < pieces.length; i++ )
{
var j = pieces[i].charAt(0).toUpperCase();
pieces[i] = j + pieces[i].substr(1).toLowerCase();
}
alert(pieces.join(" "));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 05:59 AM
What you're looking for is called Title case. You can use RegEx to do the replacement. Here's a function I found on StackOverflow.com.
function toTitleCase(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 06:18 AM
Hi Chuck,
Thanks for the response. I too actually tried with this but this works only for one string but not after the one's with space.
Thanks,
Mithuna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 06:03 AM
Try this:
var str = 'this is a test';
var pieces = str.split(" ");
for ( var i = 0; i < pieces.length; i++ )
{
var j = pieces[i].charAt(0).toUpperCase();
pieces[i] = j + pieces[i].substr(1).toLowerCase();
}
alert(pieces.join(" "));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 06:27 AM
Hi Regina,
Thank you this worked
Thanks,
Neha