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

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
Labels (2)
15 Replies
janhess
Creator II
Creator II

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;
}
Anonymous
Not applicable
Author

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
janhess
Creator II
Creator II

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.
Anonymous
Not applicable
Author

Thank you Janhess . Issue Resolved.
Regards,
Pradeep
Anonymous
Not applicable
Author

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
janhess
Creator II
Creator II

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.
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

any Suggestions. Please.
regards,
Pradeep
janhess
Creator II
Creator II

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();
}