Archive

Posts Tagged ‘Lowercase’

Uppercasing First Letters of Words, Sentences or Lines in Java

October 28th, 2009 Mehmatrix 3 comments

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 »
Bookmark and Share

Making Uppercase Each Word or First Letter of a Sentence in ASP

October 10th, 2009 Mehmatrix No comments

One of the most disturbing problems of webmasters is users which have no idea about typing a sentence. It’s should be so difficult for website owner’s to see, some silly sentences typed incorrectly on their well-designed and good-looking websites. As we all know each word of titles, names and surnames or the first letter of a sentence ALWAYS start with an uppercase letter. Unfortunately there is no such rule in caveman literature. They write the first letters of sentences or their first letter of their names small. However, you don’t need to get angry anymore. There is a little solution for these cavemen. We are going to write a function that will change first letters of each word in a sentence or the first letter of a sentence. It means, we will set the cavemen’s sentences in a correct sentence format. Also, we can convert the first letter of lines to uppercase. This can be useful when you write a poem, lyric or something like that. Let’s begin.

Firstly, there is our UppercaseTheFirstLetter() function then we will clarify it with examples.

Function 1.0: No Cavemen No Cry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
< %
function UppercaseTheFirstLetter(string, object)

if object=0 Then 'if first letter of words in sentence must be uppercased.
          splitby = " "
elseif object=1 Then 'if first letter of sentence must be uppercased.
          splitby = "."
elseif object=2 Then 'if first letter of a new line must be uppercased. (ie: poem, lyric etc.)
          splitby = "<br>"
end if

'These keywords can be changed or added manually.  

string=trim(string) 'we removed unnecessary spaces at the beginning and ending of string.
parts = Split(string,splitby) 'string is split by our intercept criteria.
'parts is an array that contains each piece of divided string.

for fi=0 to uBound(parts) 'loop 0 to size of parts array.
the_part=trim(parts(fi)) 'we removed extra spaces at the beginning and ending of part.
if len(the_part)>0 Then 'if the part is not null or not space.
uppercased = ucase(mid(the_part,1,1))&mid(the_part,2,len(the_part)-1)
'The first letter of the_part is taken and converted to uppercase,
'Rest of the_part is added at the end of the letter.
if fi>0 then output=output&splitby&uppercased else output=uppercased'string is gathered again.
end if
next
UppercaseTheFirstLetter=output
end function
%>

Click to Read Complete Article »

Bookmark and Share
eXTReMe Tracker