Hi everybody. After a long time, I am here again with my new articles. I thought it can be good to start with a little clue for PHP coders.
Usage of PHP functions is so easy and practical. However, usually we need to write our own functions while we are making our applications.
1.1) User Defined Functions in PHP
Structure 1.0:
1 2 3 4 5 6 7
| <?php
function FunctionName( arguments ){
//php codes
}
?> |
The function ends when return() statement is executed. Click to Read Complete Article »
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 »
Arrays are one of the basics of programming. We can create lots of things via arrays like matrices, databases, tables… Let’s make it shorter and start.
Array() Function in ASP
We define our arrays using the Array() function. We can store values with two different ways. We can create the array and put values in array at the same time, or we can create the array then we can initialize the values. For getting the values from arrays we have to know position of value in array. For example; second value of array, third value of array, 56th value of array etc. There is very important point that you have to know: Array() function is zero based. That mean’s first value of array is the 0th element of array.
1.1) Fixed Size Arrays
It’s better to use this usage, if you know exactly number of elements which will be used, because the compiler will know the size of array and make the processes faster.
Example 1.0: Creating the array and initializing the values at the same time.
1 2 3 4 5 6 7 8 9
| < %
dim my_array
my_array=Array("First","Second","Third","Fourth")
Response.Write "my_array(0) : "&my_array(0)&"<br/>"
Response.Write "my_array(1) : "&my_array(1)&"<br />"
Response.Write "my_array(2) : "&my_array(2)&"<br />"
Response.Write "my_array(3) : "&my_array(3)
%> |
Output of Example 1.0:
1 2 3 4
| my_array(0) : First
my_array(1) : Second
my_array(2) : Third
my_array(3) : Fourth |
This is a fixed array that includes only 4 elements that you define. You can not add another element in this array. Also, Click to Read Complete Article »
We have talked about making uppercase the first letters of words, sentences and lines in ASP before. Now, we will make the same application in JavaScript.
Let’s look at the UppercaseTheFirstLetter() function.
Function 1.0: UpperFunction.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function UppercaseTheFirstLetter(string,option){
var splitby,parts,i,uppercased;
if(option==0){splitby=" ";}
else if(option==1){splitby=".";}
else if(option==2){splitby="<br />";}
string=string.replace(/^\s+/, '').replace(/\s+$/, '');
//we removed unnecessary spaces at the beginning and ending of string.
parts = string.split(splitby);
for(i=0;i<parts .length;i++){
parts[i]=parts[i].replace(/^\s+/, '').replace(/\s+$/, '');
if(parts[i].length>0){
uppercased=parts[i].slice(0,1).toUpperCase()+parts[i].slice(1,parts[i].length);
if(i>0)output+=splitby+uppercased; 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 »
Functions are generally used to perform same operations, or compute equations. For example, suppose that you need to get an average of some numbers. What do you have to do? Are you going to write the equations all the time? A good programmer has to find the shortest way to do works. So, if we always need to get average of numbers, we write a function that evaluates average of numbers instead of writing equations for each operation. That’s why, we need functions, and that’s why you have to know how to use functions.
A function works in two different ways. It can return a value or it can do just operations. If the function makes only operations, doesn’t return a value then it is called void function, else it is called avoid function.
We use function procedure to create functions in ASP.
1.1 ) Making Avoid Functions in ASP
Structure 1.0: Structure of an avoid function in ASP
1 2 3 4 5 6 7 8 9
| < %
function FunctionName( arguments )
'…
'Operations
'…
FunctionName=value
end function
%> |
Click to Read Complete Article »
Recently Typed