Sunday, January 24, 2010

J2ME String Split Method


private String[] split(String _text, String _separator) {
Vector nodes = new Vector();
// Parse nodes into vector
int index = _text.indexOf(_separator);

while (index >= 0) {
nodes.addElement(_text.substring(0, index));
_text = _text.substring(index + _separator.length());
index = _text.indexOf(_separator);
}
// Get the last node
nodes.addElement(_text);

// Create splitted string array
String[] result = new String[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = (String) nodes.elementAt(loop);
System.out.println(result[loop]);
}
}
return result;
}

J2ME String Replace Method

J2ME doesn't have a replace method so you can use the code below. I found this function/method at http://www.itgalary.com/forum_posts.asp?TID=871 . I hope that you can use it too.


public static String replace(String _text, String _searchStr, String _replacementStr) {
// String buffer to store str
StringBuffer sb = new StringBuffer();

// Search for search
int searchStringPos = _text.indexOf(_searchStr);
int startPos = 0;
int searchStringLength = _searchStr.length();

// Iterate to add string
while (searchStringPos != -1) {
sb.append(_text.substring(startPos, searchStringPos)).append(_replacementStr);
startPos = searchStringPos + searchStringLength;
searchStringPos = _text.indexOf(_searchStr, startPos);
}

// Create string
sb.append(_text.substring(startPos,_text.length()));

return sb.toString();
}

Monday, June 1, 2009

Ruby on Rails Installation on Windows

  1. Download ruby186-25.exe at rubyinstaller.rubyforge.org
  2. Install it.
  3. First, let's check to see if you already have Ruby installed.
    Bring up a command prompt and type ruby -v.
  4. With RubyGems loaded, you can install all of Rails and its dependencies through the command line: C:\> gem install rails --include-dependencies
Keeping Rails Up-to-Date:
C:\> gem update rails


PHP Tutorial with XAMPP for Windows

Introduction


PHP is a powerful tool for making dynamic and interactive Web pages.

It is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP and other scripting languages.

In our tutorial you will learn about PHP, and how to execute scripts on your server.


XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start.


What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like Ruby on Rails, ASP, JSP and others
  • PHP scripts are executed on the server
  • PHP is an open source software
  • PHP supports many databases (MySQL, Oracle, PostgreSQL and etc.)
  • PHP is free to download and use
  • PHP files have a file extension of ".php" or ".php3"


Why PHP?
  • PHP runs on different platforms (Windows, Linux, Unix, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP is FREE to download at www.php.net
  • PHP is easy to learn and runs efficiently on the server side
What do you Need?
Note: The default installation directory is C:\xampp and C:\xampp\htdocs is the location for the PHP file.


How to Run a PHP file using XAMPP?
  • Create a PHP file then save it to C:\xampp\htdocs directory.
  • Open your browser then type "http://localhost/Your PHP File name" or "http://I.P. Address/Your PHP File name"

Basic PHP Syntax

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

Example:
<?php
//Put your code here
?>


A PHP file normally contains HTML tags, Javascript and PHP scripting code.

Example:
<html>
<body>

<?php
echo " Hello World ";
?>

</body>
</html>

Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

Note: The file must have a .php or .php3 extension else the PHP code will not be executed.


Comments in PHP
  • // to make a single-line comment
  • /* and */ to make a large comment block.
Example:
<html>
<body>

<?php

//This is a comment

/*
This is
a comment
block
*/

?>

</body>
</html>


Variable Declarations in PHP

Variables are used for storing a values, like text strings, numbers or arrays.
In PHP, a variable does not need to be declared before adding a value to it and no data type needed, PHP will automatically converts the variable to the correct data type, depending on its value.

PHP variables are start with a $ sign symbol.

Example:
$variable_name = value;


Naming Rules for PHP Variables
  • A variable name must start with a letter or an underscore "_"
  • A variable name should not contain spaces.
  • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
Valid Example:
$variable_name
$VariableName
$varName
$varName1