Hi again! Today, I’m going to give you a JAVA function that uppercases first letters of each word, sentence or line. This function is also very similar with the function which was given at this article: Making uppercase the first letters of words, sentences and lines in ASP. To understand the algorithm, take a look that.
I will name my function UppercaseTheFirstLetter() again. I like that.
Function 1.0: public static String UppercaseTheFirstLetter(String string, int option)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public static String UppercaseTheFirstLetter(String string, int option){
String splitby = null,uppercased=null,output=null;String[] parts;int i; //Variables are defined
if(option==0){splitby=" ";}
else if(option==1){splitby="\\.";} //to define the dot string we used 2 backslashes.
else if(option==2){splitby="\n";} //to define new line string we used \n
string=string.trim ();
parts = string.split(splitby);
for(i=0;i<parts .length;i++){
parts[i]=parts[i].trim();
if(parts[i].length()>0){
uppercased=parts[i].substring(0,1).toUpperCase()+parts[i].substring(1,parts[i].length());
if(i>0){
output+=splitby.replace("\\", "")+uppercased;
//if splitby criteria is a dot we need to clear the backslash \.
}else{
output=uppercased;
}
}
}
return output;
} |
This function is an avoid function that makes the first letters of all separated words, sentences or lines uppercased, then
Click to Read Complete Article »
Before giving structures, we need to notice a little detail about making database connections in Java. All database connections must be stated in try and catch statements, because there is a possibility of getting an exception. That’s way, we try to make our connection in try statement. If our connection attempt fails, that means there is an exception, and the exceptions must be catched.
1.1) MS SQL Connection in Java
Example 1.1: MakingConnections.java Click to Read Complete Article »
Recently Typed