Feb 11 2014

Abhishek Jaiswal

C# String Functions and Properties

Share it now!

Learn C#In C# programming, string is another kind of data type that represents Unicode Characters. It is the alias of System.String however, you can also write System.String instead of string. It is the sequence of character in which each character is a Unicode character.

There is no difference between string and String because string is the alias of System.String. Most of the developers get confused what to use between sting and String. Technically there is no difference between them and they can use any of them. However, you will have to use “using System” to use the String in C#. Another difference is String is a class name whereas string is a reserved keyword. You should always use string instead of String.

List of C# String Functions are given below:

 

String Functions Definitions
Clone() Make clone of string.
CompareTo() Compare two strings and returns integer value as output. It returns 0 for true and 1 for false.
Contains() The C# Contains method checks whether specified character or string is exists or not in the string value.
EndsWith() This EndsWith Method checks whether specified character is the last character of string or not.
Equals() The Equals Method in C# compares two string and returns Boolean value as output.
GetHashCode() This method returns HashValue of specified string.
GetType() It returns the System.Type of current instance.
GetTypeCode() It returns the Stystem.TypeCode for class System.String.
IndexOf() Returns the index position of first occurrence of specified character.
ToLower() Converts String into lower case based on rules of the current culture.
ToUpper() Converts String into Upper case based on rules of the current culture.
Insert() Insert the string or character in the string at the specified position.
IsNormalized() This method checks whether this string is in Unicode normalization form C.
LastIndexOf() Returns the index position of last occurrence of specified character.
Length It is a string property that returns length of string.
Remove() This method deletes all the characters from beginning to specified index position.
Replace() This method replaces the character.
Split() This method splits the string based on specified value.
StartsWith() It checks whether the first character of string is same as specified character.
Substring() This method returns substring.
ToCharArray() Converts string into char array.
Trim() It removes extra whitespaces from beginning and ending of string.

Examples of C# String Function:

Output

SUMMARY

In this section you learned about different types of C sharp string function and properties like Clone(), CompareTo(), Contains(), EndsWith(), Equals(), GetHashCode(), GetType(), GetTypeCode(), IndexOf(), ToLower(), ToUpper(), Insert(), IsNormalized(), LastIndexOf(), Length, Remove(), Replace(), Split(), StartsWith(), Substring(), ToCharArray() and Trim(). These all functions are the essential thing that should be known by a good C# programmer

Permanent link to this article: http://www.zappmania.in/2014/02/11/c-string-functions-properties.html/

Dec 19 2013

Abhishek Jaiswal

Learn HTML5 – Web Forms 2.0

Share it now!

Learn HTML5 - Web Forms 2.0

Learn HTML5 – Web Forms 2.0

Web Forms 2.0 is an extension to the forms features found in HTML4. Form elements and attributes in HTML5 provide a greater degree of semantic mark-up than HTML4 and remove a great deal of the need for tedious scripting and styling that was required in HTML4.

 

The <input> element in HTML4

HTML4 input elements use the type attribute to specify the data type. HTML4 provides following types:

 

Type Description
text A free-form text field, nominally free of line breaks.
password A free-form text field for sensitive information, nominally free of line breaks.
checkbox A set of zero or more values from a predefined list.
radio An enumerated value.
submit A free form of button initiates form submission.
file An arbitrary file with a MIME type and optionally a file name.
image A coordinate, relative to a particular image’s size, with the extra semantic that it must be the last value selected and initiates form submission.
hidden An arbitrary string that is not normally displayed to the user.
select An enumerated value, much like the radio type.
textarea A free-form text field, nominally with no line break restrictions.
button A free form of button which can initiates any event related to button.
Type Description

The <input> element in HTML5

Apart from the above mentioned attributes, HTML5 input elements introduced several new values for the type attribute. These are listed below.

 

Type Description
datetime A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601 with the time zone set to UTC.
datetime-local A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601, with no time zone information.
date A date (year, month, day) encoded according to ISO 8601.
month A date consisting of a year and a month encoded according to ISO 8601.
week A date consisting of a year and a week number encoded according to ISO 8601.
time A time (hour, minute, seconds, fractional seconds) encoded according to ISO 8601.
number This accepts only numerical value. The step attribute specifies the precision, defaulting to 1.
range The range type is used for input fields that should contain a value from a range of numbers.
email This accepts only email value. This type is used for input fields that should contain an e-mail address. If you try to submit a simple text, it forces to enter only email address in email@example.com format.
url This accepts only URL value. This type is used for input fields that should contain a URL address. If you try to submit a simple text, it forces to enter only URL address either in http://www.example.com format or in http://example.com format.
Type Description

The <output> element

HTML5 introduced a new element <output> which is used to represent the result of different types of output, such as output written by a script.

You can use the for attribute to specify a relationship between the output element and other elements in the document that affected the calculation (for example, as inputs or parameters). The value of the for attribute is a space-separated list of IDs of other elements.

The required attribute

Now you do not need to have javascript for client side validations like empty text box would never be submitted because HTML5 introduced a new attribute called required which would be used as follows and would insist to have a value:

The placeholder attribute

HTML5 introduced a new attribute called placeholder. This attribute on <input> and <textarea> elements provides a hint to the user of what can be entered in the field. The placeholder text must not contain carriage returns or line-feeds.

Here is the simple syntax for placeholder attribute:

The autofocus attribute

This is a simple one-step pattern, easily programmed in JavaScript at the time of document load, automatically focus one particular form field.

HTML5 introduced a new attribute called autofocus which would be used as follows:

Permanent link to this article: http://www.zappmania.in/2013/12/19/learn-html5-web-forms-2-0.html/

Dec 19 2013

Abhishek Jaiswal

Learn HTML 5 – Events

Share it now!

Learn HTML 5 - Events

Learn HTML 5 – Events

When a user visit your website, they do things like click on text and images and given links, hover over things etc. These are examples of what JavaScript calls events.

We can write our event handlers in Javascript or vbscript and you can specify these event handlers as a value of event tag attribute. The HTML5 specification defines various event attributes as listed below:

There are following attributes which can be used to trigger any javascript or vbscript code given as value, when there is any event occurs for any HTM5 element.

Attribute Value Description
offline script Triggers when the document goes offline
onabort script Triggers on an abort event
onafterprint script Triggers after the document is printed
onbeforeonload script Triggers before the document loads
onbeforeprint script Triggers before the document is printed
onblur script Triggers when the window loses focus
oncanplay script Triggers when media can start play, but might has to stop for buffering
oncanplaythrough script Triggers when media can be played to the end, without stopping for buffering
onchange script Triggers when an element changes
onclick script Triggers on a mouse click
oncontextmenu script Triggers when a context menu is triggered
ondblclick script Triggers on a mouse double-click
ondrag script Triggers when an element is dragged
ondragend script Triggers at the end of a drag operation
ondragenter script Triggers when an element has been dragged to a valid drop target
ondragleave script Triggers when an element leaves a valid drop target
ondragover script Triggers when an element is being dragged over a valid drop target
ondragstart script Triggers at the start of a drag operation
ondrop script Triggers when dragged element is being dropped
ondurationchange script Triggers when the length of the media is changed
onemptied script Triggers when a media resource element suddenly becomes empty.
onended script Triggers when media has reach the end
onerror script Triggers when an error occur
onfocus script Triggers when the window gets focus
onformchange script Triggers when a form changes
onforminput script Triggers when a form gets user input
onhaschange script Triggers when the document has change
oninput script Triggers when an element gets user input
oninvalid script Triggers when an element is invalid
onkeydown script Triggers when a key is pressed
onkeypress script Triggers when a key is pressed and released
onkeyup script Triggers when a key is released
onload script Triggers when the document loads
onloadeddata script Triggers when media data is loaded
onloadedmetadata script Triggers when the duration and other media data of a media element is loaded
onloadstart script Triggers when the browser starts to load the media data
onmessage script Triggers when the message is triggered
onmousedown script Triggers when a mouse button is pressed
onmousemove script Triggers when the mouse pointer moves
onmouseout script Triggers when the mouse pointer moves out of an element
onmouseover script Triggers when the mouse pointer moves over an element
onmouseup script Triggers when a mouse button is released
onmousewheel script Triggers when the mouse wheel is being rotated
onoffline script Triggers when the document goes offline
onoine script Triggers when the document comes online
ononline script Triggers when the document comes online
onpagehide script Triggers when the window is hidden
onpageshow script Triggers when the window becomes visible
onpause script Triggers when media data is paused
onplay script Triggers when media data is going to start playing
onplaying script Triggers when media data has start playing
onpopstate script Triggers when the window’s history changes
onprogress script Triggers when the browser is fetching the media data
onratechange script Triggers when the media data’s playing rate has changed
onreadystatechange script Triggers when the ready-state changes
onredo script Triggers when the document performs a redo
onresize script Triggers when the window is resized
onscroll script Triggers when an element’s scrollbar is being scrolled
onseeked script Triggers when a media element’s seeking attribute is no longer true, and the seeking has ended
onseeking script Triggers when a media element’s seeking attribute is true, and the seeking has begun
onselect script Triggers when an element is selected
onstalled script Triggers when there is an error in fetching media data
onstorage script Triggers when a document loads
onsubmit script Triggers when a form is submitted
onsuspend script Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdate script Triggers when media changes its playing position
onundo script Triggers when a document performs an undo
onunload script Triggers when the user leaves the document
onvolumechange script Triggers when media changes the volume, also when volume is set to “mute”
onwaiting script Triggers when media has stopped playing, but is expected to resume

Permanent link to this article: http://www.zappmania.in/2013/12/19/learn-html-5-events.html/

Older posts «

Powered By Indic IME