Convert string into Camel case format

0
Hello All, I need to convert string in to  Camel case . Let say I’m having Textbox to fill the form . Whatever value we are entering in the text box should be changed into camel case , only when the user on leaves from the text box .  Ex: Input – “hello”   , Output – “Hello” Is there any functions available to convert string value into camel case .  If you have any other solution than function please let me know .   Thanks in Advance!
asked
2 answers
0

If you want the first char to be uppercase, you could check and trim the input first, then change it to something like:

substring(toUpperCase($inputString), 0, 1) + substring(toLowerCase($inputString), 1)

Check out the substring and other string functions in the documentation.

Edit: correction applied

answered
0

Or you can use a JS Action to convert the String, as shown in the picture below:

 

 

JSA_ConvertToCamelCase

export async function JSA_ConvertToCamelCase(text) {
	// BEGIN USER CODE
	return text
        .replace(/\s(.)/g, function (a) {
            return a.toUpperCase();
        })
        .replace(/\s/g, '')
        .replace(/^(.)/, function (b) {
            return b.toLowerCase();
        });
	// END USER CODE
}

 

JSA_ConvertToPascalCase

export async function JSA_ConvertToPascalCase(text) {
	// BEGIN USER CODE
	return text.replace(/(\w)(\w*)/g,
        function(g0,g1,g2){
			return g1.toUpperCase() + g2.toLowerCase();
		}).replace(/\s/g, '');
	// END USER CODE
}

 

 

answered