0

I have two questions

1. How do I use a Replace() function in JSP
e.g.
String strName = "My name is";
String strName2 = replace(strName, "is", "is Michael");

2. How do I make a string to start with a capital letter

e.g.
I want david to be David

Thank you.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by peter_budo
0

replace() method is for switching characters or character seqeuances. However your example shows switching of strings/regular expresions so there is no point in using it. In this case you should use replaceAll(String regex, String replacement) .You have to be carefull with it, as it will be replace any matching expresion with your replacement string.

String strName = "My name is";
String expression = "is";
String replacement = "is Michael";
String strName2 = strName.replace(expression, replacement);

For second question you have to locate first the word of which you wish to change first character and can do something like this

String str = "david";
String str2 = 	str.replaceFirst( Character.toString(str.charAt(0)), Character.toString(str.charAt(0)).toUpperCase() );

Note please, that String str was in this case declared, where in your case you will have to locate it somehow!

0

Problem is that michael did not mentioned any DB usage and the recomended answer by you is only for Oracle/PLSQL.Also this function change all words to start with capital letter where from michael post I got impression that he want to do it only on certain words.
However you had a valid sugestion

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.