C# .NET - four important function of string in c#?

Asked By aman on 14-Oct-11 12:54 AM
hi all,
 i want to known the four important function of the string in c#...

please give me some example so that it can help me in much better manner.

thanks
Riley K replied to aman on 14-Oct-11 12:56 AM


There are hundred's of functions in C#, out of them what you want to know

Each of it has got its own significance.
Jitendra Faye replied to aman on 14-Oct-11 12:57 AM
Strings are the most important data types in computer languages. That is why we dedicate a whole chapter to working with strings in C#.

For functions follow these links-
http://zetcode.com/language/csharptutorial/strings/
http://msdn.microsoft.com/en-us/library/s1wwdcbf%28v=VS.71%29.aspx
Hope this will  help you.
smr replied to aman on 14-Oct-11 12:57 AM
HI

these are the functions

public methodhttp://msdn.microsoft.com/en-us/library/system.string.clone%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Returns a reference to this instance of http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.compare%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Compares two specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx objects.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.compareordinal%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Compares two http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx objects by evaluating the numeric values of the corresponding http://msdn.microsoft.com/en-us/library/system.char%28v=VS.71%29.aspx objects in each string.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.compareto%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Compares this instance with a specified object.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.concat%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Concatenates one or more instances of http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx, or the String representations of the values of one or more instances of http://msdn.microsoft.com/en-us/library/system.object%28v=VS.71%29.aspx.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.copy%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Creates a new instance of http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx with the same value as a specified String.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.copyto%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.endswith%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Determines whether the end of this instance matches the specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.equals%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Overridden. Determines whether two http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx objects have the same value.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.format%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Replaces each format item in a specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx with the text equivalent of a corresponding object's value.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.getenumerator%28v=VS.71%29.aspx Retrieves an object that can iterate through the individual characters in this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.gethashcode%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overridden. Returns the hash code for this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.object.gettype%28v=VS.71%29.aspx (inherited from Object)

Supported by the .NET Compact Framework.

Gets the http://msdn.microsoft.com/en-us/library/system.type%28v=VS.71%29.aspx of the current instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.gettypecode%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Returns the http://msdn.microsoft.com/en-us/library/system.typecode%28v=VS.71%29.aspx for class http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.indexof%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Reports the index of the first occurrence of a http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx, or one or more characters, within this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.indexofany%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Reports the index of the first occurrence in this instance of any character in a specified array of Unicode characters.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.insert%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Inserts a specified instance of http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx at a specified index position in this instance.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.intern%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Retrieves the system's reference to the specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.isinterned%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Retrieves a reference to a specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodstatic (Shared in Visual Basic)http://msdn.microsoft.com/en-us/library/system.string.join%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Concatenates a specified separator http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx between each element of a specified String array, yielding a single concatenated string.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.lastindexof%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Reports the index position of the last occurrence of a specified Unicode character or http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx within this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.lastindexofany%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Reports the index position of the last occurrence in this instance of one or more characters specified in a Unicode array.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.padleft%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Right-aligns the characters in this instance, padding on the left with spaces or a specified Unicode character for a specified total length.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.padright%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Left-aligns the characters in this string, padding on the right with spaces or a specified Unicode character, for a specified total length.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.remove%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Deletes a specified number of characters from this instance beginning at a specified position.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.replace%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Replaces all occurrences of a specified Unicode character or http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx in this instance, with another specified Unicode character or String.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.split%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Identifies the substrings in this instance that are delimited by one or more characters specified in an array, then places the substrings into a http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx array.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.startswith%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Determines whether the beginning of this instance matches the specified http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.substring%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Retrieves a substring from this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.tochararray%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Copies the characters in this instance to a Unicode character array.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.tolower%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Returns a copy of this http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx in lowercase.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.tostring%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Overridden. Converts the value of this instance to a http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.toupper%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Returns a copy of this http://msdn.microsoft.com/en-us/library/system.string%28v=VS.71%29.aspx in uppercase.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.trim%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Overloaded. Removes all occurrences of a set of specified characters from the beginning and end of this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.trimend%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Removes all occurrences of a set of characters specified in an array from the end of this instance.
public methodhttp://msdn.microsoft.com/en-us/library/system.string.trimstart%28v=VS.71%29.aspx

Supported by the .NET Compact Framework.

Removes all occurrences of a set of characters specified in an array from the beginning of this instance.
Reena Jain replied to aman on 14-Oct-11 01:10 AM
hi,

hi,

To write efficient string handling functions, it is important to understand the characteristics of string objects in C#.
String Characteristics
 
First and foremost it is important to know that strings in .NET are class objects. There is no difference between the types System.String and string, they are both class objects. Unlike value types, class objects are stored in the heap (instead of the stack). This is an important fact because it means that creating a string object can trigger garbage collection, which is costly in terms of performance. In terms of string functions, this means we want to avoid creating new strings as much as possible.
 
However that is easier said than done. Another important thing about strings in .NET is that they are immutable. This means string objects cannot be modified. To edit a string object, you have to instead create a new string that will have the modification.
 
http://www.dotnetcurry.com/ShowArticle.aspx?ID=463
Chintan Vaghela replied to aman on 14-Oct-11 01:26 AM
Hi,

1 . Split

Example
using System;

class Program
{
    static void Main()
    {
	string s = "there is a cat";
	//
	// Split string on spaces.
	// ... This will separate all the words.
	//
	string[] words = s.Split(' ');
	foreach (string word in words)
	{
	    Console.WriteLine(word);
	}
    }
}

Output

there
is
a
cat

2. CopyTo

Example

using System;

class Program
{
    static void Main()
    {
	// Declare a string constant and an output array.
	string value1 = "Dot Net Perls";
	char[] array1 = new char[3];
	// Copy the fifth, sixth, and seventh characters to the array.
	value1.CopyTo(4, array1, 0, 3);
	// Output the array we copied to.
	Console.WriteLine("--- Destination array ---");
	Console.WriteLine(array1.Length);
	Console.WriteLine(array1);
    }
}

Output

--- Destination array ---
3
Net
3. StartsWith

Example
using System;

class Program
{
    static void Main()
    {
	// The input string.
	string input = "http://site.com/test.html";

	// See if input matches one of these starts.
	if (input.StartsWith("http://www.site.com") ||
	    input.StartsWith("http://site.com"))
	{
	    // Write to the screen.
	    Console.WriteLine(true);
	}
    }
}

Output

True
4. Replace Example
using System;

class Program
{
    static void Main()
    {
	const string s = "Darth Vader is scary.";
	Console.WriteLine(s);

	// Note:
	// You must assign the result of Replace to a new string.
	string v = s.Replace("scary", "not scary");
	Console.WriteLine(v);
    }
}

Output

Darth Vader is scary.
Darth Vader is not scary.

If you want to know more function visit folloiwng site

http://www.dotnetperls.com/string
Hope this helps!