Showing posts with label print. Show all posts
Showing posts with label print. Show all posts

Saturday, 26 October 2013

How to split complex strings in corona SDK

This session will teach you about splitting complex string of data separated with some characters. Lets assume that you have a string as House;home,40|Bed,20|Mirror,10. Now we will show you how to split each word and assigning each to a table.



  local myString = "House;home,40|Bed,20|Mirror,10"
  local myTable = {}
  for word in string.gmatch(myString, '([^,|]+)') do
     -- 'myTable' contains the data you need
    myTable[#myTable+1]=word print( myTable[#myTable] )
   end


Hence you will get the items as each table elements, as:
  
  myTable[1] = House
  myTable[2] = home
  myTable[3] = 40
  myTable[4] = Bed
  myTable[5] = 20
  myTable[6] = Mirror
  myTable[7] = 10

Wednesday, 7 August 2013

How to generate a random number in corona SDK

We can use math.random() for the purpose of generating random numbers in corona SDK.
There are 3 main types for this call. They are:

1) Witout any argument:
        math.random()
        -- This will return a pseudo random number in the range of [0,1)
   
2) With one argument:
        math.random(a)
        -- This will return a pseudo random number in the range of [0,a]
   
        eg: print(math.random(5))  ----> return a number between 1 and 5 (both inclusive)
   
3) With two arguments:
        math.random(a,b)
        -- This will return a pseudo random number in the range of [a,b]
   
        eg: print(math.random(2,10))  ----> return a number between 2 and 10 (both inclusive)

Saturday, 8 June 2013

How to print data : PHP

You can use 'echo' to print string, variables, etc. in php. 

Syntax:

        echo "print it...";                       // Output------------->  print it...
        echo '<br/>';                           // prints a new line/enter

        $var_1 = 10;
        $var_2 = 3.14;
        $var_3 = "myString";
        echo $var_1;                           //  Output (number)------->  10
        echo $var_3;                           //  Output (string)------->  myString
        echo "$var_1 + $var_2";         //  Output (sum number)-------> 13.14
       
       echo '$var_1 + $var_2';          //  Output (string)-------> $var_1 + $var_2
       
       echo "$var_1 + $var_2 = ".($var_1 + $var_2);  
       // Output ---------> $var_1 + $var_2 = 13.14


      Note: dot(.) character is used to concant/join strings in php.
 

Friday, 31 May 2013

How to print a line in console: Xcode

To print a line in console, you can use the following syntax:

Syntax:

          NSLog(@"Show this line in console...");