הפונקציה מקבלת מחרוזת ומחזירה את המחרוזת כשבראש כל "מילה" אות גדולה. הפונקציה בודקת בעצם היכן יש הפרדה בין מילים: תחילת שורה חדשה או הפרדה בין המילים במשפט (רווח או מקף), בכל מילה במשפט תוגדל האות הראשונה. הפונקציה עוברת על המחרוזת החל מהתו הראשון ועד לתו הלפני אחרון ואם נמצא תו רווח, מקף או רצף התווים הידוע לשמצה, הפונקציה תיצור מחרוזת חדשה ע"י חיבור חלק המחרוזת כולל התו או התווים המפרידים, האות הראשונה המוגדלת במילה המופרדת והמשכה של המחרוזת עד לסופה.
פונקציות בהן נעשה שימוש:
UCase - הופכת מחרוזת תווים של אותיות באנגלית לאותיות גדולות UCase(string_name)
Mid - מחזירה מספר תווים מהחרוזת החל ממקום מסוים Mid(string_name, start, lenght)
Right - מחזירה מספר תווים מסוף המחרוזת Right(string_name, lenght)
Len - מחזירה את מספר התווים במחרוזת Len(string_name)
str="ya ya ya coco jumbo"
UCase(str) = "YA YA YA COCO JUMBO"
Mid(str, 3, 10) = " ya ya coc"
Right(str ,9) = "co jumbo"
Len(str) = 19
הערה: רצף התווים chr(13) -ו chr(10) נוצר ע"י הקלדת <ENTER> חזרתו של הסמן לתחילת השורה והזנת שורה חדשה
דוגמא:
normal text:
this is a fucked-up text
you can't see the connection
between the sentences
because the sky is blue.
Capitalized Text:
This Is A Fucked-Up Text
You Can't See The Connection
Between The Sentences
Because The Sky Is Blue.
איך עושים את זה?
הנה הקוד מקור:
<%@ Language=VBScript %>
<%
Function Capitalize(str)
Dim t
t = str
If t <> "" Then
t = UCase(Mid(t, 1, 1)) & Right(t, Len(t)-1)
For i = 1 To Len(t)-1
If Mid(t, i, 2) = Chr(13) + Chr(10) Then
' Capitilize words preceded by "carrige return" + "linefeed" combination.
t = Mid(t, 1, i+1) & UCase(Mid(t, i+2, 1)) & Mid(t, i+3, Len(t)-i-2)
End If
If (Mid(t, i, 1) = " ") or (Mid(t, i, 1) = "-") Then
' Capitalize words preceded by a space.
t = Mid(t, 1, i) & UCase(Mid(t, i+1, 1)) & Mid(t, i+2, Len(t)-i-1)
End If
Next
End If
Capitalize = t
End Function
%>
<% text = _
"this is a fucked-up text" & _
" you can't see the connection" & _
" between the sentences" & _
" because the sky is blue."
%>
Capitalize Every First Letter
normal text
<%= text %>
<%= capitalize("capitalized text")%>
<%= Capitalize(text) %>
this is a fucked-up text
you can't see the connection
between the sentences
because the sky is blue.