• Instructions to Ask a Question

    Click on the "Ask a Question" button and select the application for which you would like to ask questions.

    We have 5 different products namely - Pabbly Connect, Pabbly Subscription Billing, Pabbly Email Marketing, Pabbly Form Builder, Pabbly Email Verification.

    The turnaround time is 24 hrs (Business Hours - 10.00 AM to 6.00 PM IST, Except Saturday and Sunday). So your kind patience will be highly appreciated!

    🚀🚀Exclusive Discount Offer

    Just in case you're looking for any ongoing offers on Pabbly, you can check the one-time offers listed below. You just need to pay once and use the application forever -
     

    🔥 Pabbly Connect One Time Plan for $249 (🏆Lifetime Access) -  View offer 

    🔥 Pabbly Subscription Billing One Time Plan for $249 (🏆Lifetime Access) - View offer

Capitalize despite mistake?

Stuart

Member
A very common thing people do is to write the initials without spaces like "E.B. White" instead of "E. B. White".
Can we make the capitalize function capitalize both letters? (i.e. any letter after a period or space gets capitalized)

1702382311451.png
 

Subin

Well-known member
Staff member
Hey @Stuart !

Sure, you can use the "Code by Pabbly" module to create such a conversion-

1702386320308.png


You can refer to this video tutorial on how this works-


Do check and let us know about it.
 

Stuart

Member
Edit:
I think this works!

function convertString(str) {
str = str.toLowerCase();
let words = str.split(' ');
for (let i = 0; i < words.length; i++) {
let word = words;
word = word.charAt(0).toUpperCase() + word.slice(1);
word = word.replace(/(\.| |-)(\w)/g, function(match, p1, p2) {
return p1 + p2.toUpperCase();
});
word = word.replace(/\b(i|ii|iii|iv|v|vi|vii|viii|ix|x)\b/gi, function(match) {
return match.toUpperCase();
});
words = word;
}
str = words.join(' ');
return str;
}

let input = "4. Result : e.b. wHite E.b. white jr. SR eeee beee wHITE III";
let refinedString = convertString(input);
return refinedString;
 
Last edited:

Stuart

Member
this Capitalizes the name and splits it into parts as needed!
we can add another line for titles if necessary!

function convertString(str) {
str = str.toLowerCase();
let words = str.split(' ');
for (let i = 0; i < words.length; i++) {
let word = words;
word = word.charAt(0).toUpperCase() + word.slice(1);
word = word.replace(/(\.| |-)(\w)/g, function(match, p1, p2) {
return p1 + p2.toUpperCase();
});
word = word.replace(/\b(i|ii|iii|iv|v|vi|vii|viii|ix|x)\b/gi, function(match) {
return match.toUpperCase();
});
words = word;
}
str = words.join(' ');
return str;
}

function parseName(name) {
const words = name.split(' ');
const suffixes = ['jr', 'jr.', 'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x'];
let lastName = '';
let firstName = '';
let restName = '';
let suffix = '';
if (words.length > 0) {
if (suffixes.includes(words[words.length - 1].toLowerCase())) { suffix = words.pop();
}
if (words.length > 0) { lastName = words.pop();
}
if (words.length > 0) { firstName = words.shift();
}
if (words.length > 0) { restName = words.join(' '); } }
restName = restName+' '+lastName;
if (suffix != "") { restName= restName+" "+suffix;
}
return {name, lastName, firstName, restName, suffix, };
}

let input = "e.b. wHite jr.";
let refinedString = convertString(input);
return parseName(refinedString);
 
Top