Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
profuse
Creator

How do you Uppercase the first letter of every word in a string?

Hi,
I'm still new to Talend.
I have a CVS file with a column that contains a persons full name in all uppercase i.e. STEVE CHARLES SMITH
I would like to edit this column to leave the first letter of each word in uppercase and lowercase the remaining letters of each word so the results look like this: Steve Charles Smith
I tried using the following code in tMap but it only uppercase's the first letter of the first word and the remaining letters are all in lowercase i.e. Steve charles smith
Current Code:
row1.Full_Name.toLowerCase().replaceFirst( "" ,

row1.Full_Name.substring(0,1).toUpperCase())
Does anyone know how to make the results look like Steve Charles Smith?
Thanks for your time.
Labels (2)
7 Replies
Anonymous
Not applicable

Hi,
Its wondering that there is no direct java method to convert each token to initcap.
I know this could not be the perfect solution but try this as a temporary solution to solve your problem.
use the below code in tjava and make changes accordingly.
StringBuilder ff = new StringBuilder();
String inputString =input_row.name ;
for(String f: inputString.split(" "))
{
if(ff.length()>0)
{
ff.append(" ");
}
ff.append(f.substring(0,1).toUpperCase()).append(f.substring(1,f.length()).toLowerCase());
}
output_row.name = ff.toString();
//System.out.println(output_row.name);
-Bhanu
Anonymous
Not applicable

there is open source lib, but you need to add in Talend to use it, if you do that below method will work for you.
org.apache.commons.lang.WordUtils.capitalizeFully(text, ' ');
profuse
Creator
Author

Umesh,
I don't know anything about the Java language and not sure where to download org.apache.commons.lang.WorldUtils but I tried doing the following:
In the plugins folder, I created the following folder org.apache.commons.lang. And downloaded the WorldUtils.java into this folder
I got the WorldUtils.java code from this website []%29
Then in tMap I coded the following:
org.apache.commons.lang.capitalizeFully(row1.Provider_Last_Name__Legal_Name, ' ');
Note: row1.Provider_Last_Name__Legal_Name is the column containg the name (text)
But when running the job I get the following error: org.apache.commons.lang can not be resolved
Can you help?
Anonymous
Not applicable

Go to the  apache.commons site and downloaded Jar instead of .java file, then place this jar to the lib folder, and after that use tLibraryLoad component to load this jar. it will solve your problem! you are close to the solution.
profuse
Creator
Author

Hi Umeshrakhe,
I went to the apache.commons site and d ownload org-apache/org-apache-commons-lang.jar.zip

Extracted All and copied the org-apache-commons-lang.jar to TOS_DI-Win32-r118616-V5.5.1/lib
In the job I added tlibraryload and in its basic settings next to the word Library I selected org-apache-commons-lang.jar
I then connected it to the tFileInputDeliminted with the OnSubjobOK
Then in the tMap Expression for the Last name I coded the following:
row1.Provider_Last_Name__Legal_Name.capitalizeFully(row1.Provider_Last_Name__Legal_Name, ' ');
When I run the job I get the following error: The Method capitalizeFully(String, char) is undefined for the type string.
What have I done wrong?
Do I need to add anything in the advanced settings of the tlibraryload?
How do I code the tMap Expression correctly?
Thanks
Anonymous
Not applicable

you are using it in wrong way. you have to pass arguments to below method. This method is undfined for String type that is way, it is raising error 
org.apache.commons.lang.WordUtils.capitalizeFully(row1.Provider_Last_Name__Legal_Name, ' ');

you can use above as it is. and check again.
profuse
Creator
Author

IN tMap expression I changed it as you suggested:
org.apache.commons.lang.WordUtils.capitalizeFully(row1.Provider_Last_Name__Legal_Name, ' ');

And when I run it I get the following error:
The Method capitalizeFully(String, []) in the type WordUtils is not applicable for the arguments (String, char)
I think it doesn't like putting the row1.Provider_Last_Name__Legal_Name as the String
Any ideas?