Skip to main content

Posts

Showing posts with the label format

Display formatted date/time using String.format()

In this post we explains how to display formatted calendar using String.format().Let's hae a look. Download and use... import java.util.Calendar; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView cal = (TextView)findViewById(R.id.viewdate); Calendar calendar = Calendar.getInstance(); cal.setText( String.format("%td-%tm-%tY\n", calendar, calendar, calendar) + String.format("%ty/%tm/%td\n", calendar, calendar, calendar) + String.format("%tI:%tM:%tS %tp\n", calendar, calendar, calendar, calendar) + "\n" + String.format("%tD\n", calendar) + String.format("%tc\n", calendar) + String....

Taking Random Values in Corona

Syntax for taking random numbers or values in corona has been given below. Download the code and try it... Syntax         math.random()          math.random( m )          math.random( m, n ) math.random() ---> a number between 0 and 1 math.random(m) ---> an integer between 1 and n (inclusive) math.random(m,n) ---> an integer between m and n (inclusive) math.random() ---> a number between 0 and 1 math.random(20) ---> an integer between 1 and 20 (inclusive) math.random(20, 40) ---> an integer between 20 and 40 (inclusive)

String Functions In Corona

Here is a list of string function which are very useful... string.byte() Returns the internal numerical codes of the characters in a string. string.char() Returns a string in which each character has the internal numerical code equal to its corresponding argument. string.find() Looks for the first match of a pattern in a string. If found, it returns the indices where the occurrence starts and ends; otherwise, returns nil. string.format() Returns a formatted string following the description given in its arguments. string.gmatch() Returns a pattern-finding iterator. string.gsub() Replaces all occurrences of a pattern in a string. string.len() Returns the length of a string (number of characters). string.lower() Changes uppercase characters in a string to lowercase. string.match() Extracts substrings by matching patterns in a string. string.rep() Replicates a string by returning a string that is the concatenation of n copies of a specified strin...