Thursday, January 7, 2010

DEFINATION ABOUT STRING CLASS , TOUPPER,INDEXOFF IN .NET (C SHARP)

string class:

String is a word used for a sequence or set of characters. Since set of characters are used a lot therefore a special class has been created for the programmers. Recall that a class consists of data and set functions that usually apply on data. In the case of built-in class string, the objects or instances of string consist a sequence of characters as data and a number of functions that can be applied on data. Lets discuss various functions that can be applied on string.

ToUpper:

This function converts the data held by the object to upper case


Since the data held by textBox1.Text is string therefore we have copied it into a newly created string variable named “txt”. Then “ToUpper” method has been called which will produce a new string that consist of all data converted into upper case. Since the “ToUpper” method is enclosed in the brackets of “Show”, therefore it will be interpreted that the result of “ToUpper” will be given to Show which will display it in message box. If the requirement is to display the case-updated data in the same textbox then the following could be written


IndexOf

It is often requirement to check whether a particular character is present in a string and at which location. “IndexOf” serves both the purposes. For example, a valid email (which is a string i.e. sequence of characters) must contain “@” symbol, this can be checked using the “IndexOf” method. This method will return “-1” if the string does not contain a particular symbol, “@” in this case, otherwise it will return the location at which the symbol or character exists. Following is the code that demonstrates an example.

No comments:

Post a Comment