• Instructions to Ask a Question

    For any assistance, please click the "Ask a Question" button and select the Pabbly product for which you require support.

    We offer seven comprehensive applications designed to help you efficiently manage and grow your business:

    Our support team endeavors to respond within 24 business hours (Monday to Friday, 10:00 AM to 6:00 PM IST). We appreciate your understanding and patience.

    🚀 Exclusive Lifetime Offers 🚀

    We invite you to take advantage of our special one-time payment plans, providing lifetime access to select applications:

    • 🔥 Pabbly Connect — Lifetime Access for $249View Offer
    • 🔥 Pabbly Subscription Billing — Lifetime Access for $249View Offer
    • 🔥 Pabbly Chatflow — Lifetime Access for $249View Offer

    Make a one-time investment and enjoy the advantages of robust business management tools for years to come.

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
 
P

Pabbly13

Guest
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