Question
Virtusa
US
Last activity: 19 Jan 2017 14:40 EST
Data Page Report: property formatting
We have several Data Types that are delegated to the user and there are some fields, like Desription or Type, that contain several words and user wants each word to be started with the upper case. Is there a way to format such properties in this way? Any functions? We use Pega 7.2.1
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Virtusa
US
Hi guys,
Thank you everyone for help. Below is the code I made to work, maybe it will help somebody else:
StringBuilder builder = new StringBuilder();
if (InputString == null)
return "";
String[] convertedString = InputString.toLowerCase().split(" ");
for (String name : convertedString)
{
builder.append(name.substring(0,1).toUpperCase() + name.substring(1));
builder.append(" ");
}
InputString = builder.toString().trim();
return InputString;
Pegasystems Inc.
IN
Hello Larisa,
I don't think so we have any OOTB function to achieve your requirement .
May be you can write your own function ,you can write the code as follows
StringBuilder builder = new StringBuilder();
String test ="new test";
String[] convertedString = test.split(" ");
for (String string : convertedString) {
builder.append(string.substring(0, 1).toUpperCase() + string.substring(1));
builder.append(" ");
}
test =builder.toString().trim();
System.out.println(test);
Hope it helps .
Thanks,
Arun
Virtusa
US
Thank you Arun, I'll try it.
Regards
Pegasystems Inc.
US
HI,
Please check the following two OOTB functions:
"ConvertToUpperCase" under Utilities class.
"toUpperCase" under String class.
Virtusa
US
Hi Susan. These functions convert entire string to either lower or upper case.
Blue Rose Technologies GmbH
BE
Hi ,
You can use the function to achieve your requirement :
//sample code
function test(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
console.log(test('testing'));
Hope this helps.
Pegasystems Inc.
US
Hi Larisa,
You can look into this article for the easy OOTB apache commons lang library using WordUtils.capitalize(str)
method to achieve your requirement.
Regards,
Mahesh
Accepted Solution
Virtusa
US
Hi guys,
Thank you everyone for help. Below is the code I made to work, maybe it will help somebody else:
StringBuilder builder = new StringBuilder();
if (InputString == null)
return "";
String[] convertedString = InputString.toLowerCase().split(" ");
for (String name : convertedString)
{
builder.append(name.substring(0,1).toUpperCase() + name.substring(1));
builder.append(" ");
}
InputString = builder.toString().trim();
return InputString;