Archive

Posts Tagged ‘Function’

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