
Creator
2014-12-15
04:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
674 Views
7 Replies

Anonymous
Not applicable
2014-12-16
01:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
674 Views

Anonymous
Not applicable
2014-12-16
03:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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, ' ');
674 Views

Creator
2014-12-16
11:48 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
674 Views

Anonymous
Not applicable
2014-12-17
02:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
674 Views

Creator
2014-12-17
02:39 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
674 Views

Anonymous
Not applicable
2014-12-18
02:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
you can use above as it is. and check again.
org.apache.commons.lang.WordUtils.capitalizeFully(row1.Provider_Last_Name__Legal_Name, ' ');
you can use above as it is. and check again.
674 Views

Creator
2014-12-18
12:36 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IN tMap expression I changed it as you suggested:
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?
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?
674 Views
