Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Converting strings into proper / title case using Java

Hi, how would you go about converting a string which is all upper case into capital first letter only for the whole sentence (proper/title case)? There does not seem to be a Talend string function for this and neither built-in to the basic Java libraries.

Labels (3)
25 Replies
_AnonymousUser
Specialist III
Specialist III

Hi,
Probably you can use following expression in your tMap
Expression:
----------------
row1.TitleString.toLowerCase().replaceFirst("", row1.TitleString.substring(0,1).toUpperCase())
Note:- "TitleString" is the column name.
--
Regards,
Vinod

Why would you do that.
Anonymous
Not applicable
Author

Hi, how would you go about converting a string which is all upper case into capital first letter only for the whole sentence (proper/title case)? There does not seem to be a Talend string function for this and neither built-in to the basic Java libraries.

Hi,
Probably you can use following expression in your tMap
Expression:
----------------
row1.TitleString.toLowerCase().replaceFirst("", row1.TitleString.substring(0,1).toUpperCase())
Note:- "TitleString" is the column name.
--
Regards,
Vinod
_AnonymousUser
Specialist III
Specialist III

Yes, it's a stupid and messy solution. It only works for the first word, why are you using "replaceFirst" with a regex but use the first character via substring as a replacement anyway?
Anonymous
Not applicable
Author

Hello All
I am trying to ensure that certain fields in my pre-load database contain proper (or title) case. Having read several posts on the subject I think the route I should take is as follows;
tlibraryload > tmssqlInput > tJavaRow > tmap > tlogrow
In tlibraryLoad my settings are:
Basic Settings > library > commons-lang-2.6.jar
Advanced Settings > Lib > empty
Advanced Setting > Import > //import org.apache.commons.lang.WordUtils;
In TJavaRow my settings are:
Basic Settings > Code >
OutputRow.File_Detail_Header_Id = InputRow.File_Detail_Header_Id;
OutputRow.File_Detail_Id = InputRow.File_Detail_Id;
OutputRow.Forenames = WordUtils.capitalizeFully(InputRow.Forenames);
Advanced Settings > Import > //import org.apache.commons.lang.WordUtils;
The error messages I am getting:
Exception in thread "main" java.lang.Error: java.lang.Error: Unresolved compilation problems:
WordUtils cannot be resolved
FileDetailRead cannot be resolved to a variable
Syntax error on token "OutputRow", delete this token
OutputRow is what I called the connector between TJavaRow and TMap and is spelt and the casing are both corrrect.
Where have I gone wrong?
_AnonymousUser
Specialist III
Specialist III

did something like this a little while back, so i thought i'll post it - even though it seems like the tread is kinda dead
under Code -> Routines -> right click and add your own custom routine, then you have two options
1. right click the new routine and click on Edit routine libraries and add your required lib in here (per my experience routine libs work better than trying to load something into a job), then just create wrapper functions for the lib methods in this routine, and call them via your newly defined wrapper methods.
2. Doing proper case is not that complex of a job once your writing java code (you'll find many examples of this on google), so you can create your own version of a properCase function in this new class, which can implement other complex rules you might need as well - and then just use that in your tMap, Flow etc. no need to integrate with any external API.
hope this helps.
Anonymous
Not applicable
Author

In the talendforge there is an implementation of StringUtils but it doesn't appear supported for DI 6.3. I was wondering since the original posting in 2011 is there a updated library that should be used with tLoadLibrary component?

The original poster suggested the values below but when I browse the list of libraries available I see others and from the apache documents capitalize looks to be available in most

 0683p000009Lu9Y.png

commons-lang-2.5.jar 

and

import the class 

org.apache.commons.lang.StringUtils