Issue with string Handling Function

One Star

Issue with string Handling Function

Hello -
Good Morning. I have a name abhishek sharma, So here I need to get the output as Abhishek Sharma
First name & lastname first letters should be in uppercase.
Any Suggestions.
Regards,
Pradeep
One Star

Re: Issue with string Handling Function

Set this up as a routine.
/**
* titleCase() Changes a string to Title case.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} String("fred") input: the string to change to title case
*
* {example} titleCase("fred") # Fred
*
*/
public static String titleCase(String string){
String result = "";
for (int i = 0; i < string.length(); i++){
String next = string.substring(i, i + 1);
if (i == 0){
result += next.toUpperCase();
} else {
result += next.toLowerCase();
}
}
return result;
}
One Star

Re: Issue with string Handling Function

Thank you for your Quick response.
I tried doing it but i couldn't, Do I have any other way to do with string handling functions? Please help me.
Regards,
Pradeep
One Star

Re: Issue with string Handling Function

Couldn't what? Set it up as a routine? You'll need to change the category. Then use the routine in the tMap rule to change to title case.
One Star

Re: Issue with string Handling Function

Thank you Janhess . Issue Resolved.
Regards,
Pradeep

Re: Issue with string Handling Function

Another way you could do this is using the following code in your tMap
StringHandling.UPCASE(StringHandling.LEFT(row4.test,1))+StringHandling.RIGHT(row4.test,StringHandling.LEN(row4.test)-1)

Regards
Brandon
One Star

Re: Issue with string Handling Function

Another way you could do this is using the following code in your tMap
StringHandling.UPCASE(StringHandling.LEFT(row4.test,1))+StringHandling.RIGHT(row4.test,StringHandling.LEN(row4.test)-1)

Regards
Brandon

Only works if there are 2 words to change.
One Star

Re: Issue with string Handling Function

Hey Janhess-
Good afternoon,
My output : Abhishek Sharma
That Routine works fine but my Issue is with 2nd word,
routine which you have sent me gives Abhishek sharma, But I need 's' also in caps. Can I get updated routine please.
Regards,
Pradeep
One Star

Re: Issue with string Handling Function

any Suggestions. Please.
regards,
Pradeep
One Star

Re: Issue with string Handling Function

I'm sure I tested it.
Try this
public static String toTitleCase(String input) {
StringBuilder titleCase = new StringBuilder();
boolean nextTitleCase = true;
for (char c : input.toCharArray()) {
if (Character.isSpaceChar(c)) {
nextTitleCase = true;
} else if (nextTitleCase) {
c = Character.toTitleCase(c);
nextTitleCase = false;
}
else {
c = Character.toLowerCase(c);
}
titleCase.append(c);
}
return titleCase.toString();
}
One Star

Re: Issue with string Handling Function

@ Janhess -
Thank you Very much For your help. Issue Resolved.
How did you do that ? Appreciate it , It is very tough for me to write coding part (routines), I am new to Talend, Do u suggest me some online links.
Regards,
Pradeep
One Star

Re: Issue with string Handling Function

@ Janhess -
Thank you Very much For your help. Issue Resolved.
How did you do that ? Appreciate it , It is very tough for me to write coding part (routines), I am new to Talend, Do u suggest me some online links.
Regards,
Pradeep

Googled it. You should try it!
One Star

Re: Issue with string Handling Function

The code here will also convert the rest of the string (after the first letter) to small cap:
StringHandling.UPCASE(StringHandling.LEFT(row.Family,1))+
StringHandling.DOWNCASE(StringHandling.RIGHT(row.Family,StringHandling.LEN(row.Family)-1))
One Star

Re: Issue with string Handling Function

But it doesn't solve the problem that was raised. It doesn't convert all words.
One Star

Re: Issue with string Handling Function

Hi,
There is a capitalizeFully method in the Commons Lang JAR that ships with Talend. The method is in a class called WordUtils. From the documentation...
WordUtils.capitalizeFully(null) = null
WordUtils.capitalizeFully("") = ""
WordUtils.capitalizeFully("i am FINE") = "I Am Fine"
This post shows how to use the Commons Lang library in a Talend tMap. For this requirement, substitute "WordUtils" for "StringUtils" and "org.apache.commons.lang.WordUtils" for "org.apache.commons.lang.StringUtils".
http://bekwam.blogspot.com/2011/01/java-libraries-in-talend-open-studio.html
One Star

Re: Issue with string Handling Function

I find it a bit of an overhead to remember to do the tLibraryLoad all the time so I converted all the Apache string Utils to Talend Routines.