[How to] Syntax Highlighting
#1

Syntax Highlighting



C
Code:
[c]Code ...[/c]

Example:
[c]
/* C Program to print a sentence. */
#include <stdio.h>
int main()
{
printf("C Programming"); /* printf() prints the content inside quotation */
return 0;
}
[/c]

C++/C#
Code:
[cpp]Code ...[/cpp]

Example:
[cpp]
// AddTwoNumbers.cc
// Computes the sum of two numbers inputed at the keyboard.

#include <iostream>
using namespace std;

int main()
{
int a, b, total ;

cout << "Input numbers to be added: " << endl;
cin >> a >> b ;
total = a + b ;
cout << "The sum is " << total << endl;
return 0;
}
[/cpp]


Java
Code:
[java]Code ...[/java]

Example:
[java]
public class FindEvenOrOddNumber {

public static void main(String[] args) {

//create an array of 10 numbers
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};

for(int i=0; i < numbers.length; i++){

/*
* use modulus operator to check if the number is even or odd.
* If we divide any number by 2 and reminder is 0 then the number is
* even, otherwise it is odd.
*/

if(numbers[i]%2 == 0)
System.out.println(numbers[i] + " is even number.");
else
System.out.println(numbers[i] + " is odd number.");

}

}
}
[/java]


Javascript
Code:
[js]Code ...[/js]

Example:
[js]
document.getElementById("demo").innerHTML = "Hello Dolly.";
[/js]


Batch/Shell Script
Code:
[bat]Code ...[/bat]

Example:
[bat]
@echo off
REM Next command opens Microsoft Word
start /d "C:\Program Files\Microsoft Word" WINWORD.EXE
[/bat]


SQL
Code:
[sql]Code ...[/sql]

Example:
[sql]
CREATE TABLE example_timestamp (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(100),
cur_timestamp TIMESTAMP(8)
);
[/sql]


Visual Basic
Code:
[vb]Code ...[/vb]

Example:
[vb]
Function calMax(x, y, z As Variant)

If x > y And x > z Then

calMax = Str(x)
ElseIf y > x And y > z Then
calMax = Str(y)
ElseIf z > x And z > y Then

calMax = Str(z)

End If

End Function

Private Sub Command1_Click()
Dim a, b, c
a = Val(Txt_Num1.Text)
b = Val(Txt_Num2.Text)
c = Val(Txt_Num3.Text)

Lbl_Display.Caption = calMax(a, b, c)

End Sub

Private Sub Label5_Click()

End Sub
[/vb]


HTML
Code:
[html]Code ...[/html]

Example:
[html]
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
[/html]


PHP
Code:
[php]Code ...[/php]

Example:
PHP Code:
<?php if (isset($gender) && $gender=="female") echo "checked";?>


XML
Code:
[xml]Code ...[/xml]

Example:
[xml]
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
[/xml]


INI
Code:
[ini]Code ...[/ini]

Example:
[ini]
[special_fields]
required = "email,realname,Mesg"
csvfile = "contacts.csv"
csvcolumns = "email,realname,Mesg,Date,Time"
[/ini]




Users browsing this thread: 1 Guest(s)