.

Strings in C# Assignment Help

STRINGS

  • The sequence of characters is called strings.
  • String variable is declared using string keyword
  • Actually String belongs to System.String className.

Strings in C# Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


Creating Strings:

String s1= “hai”;

String length:

The length method is used to find the length of given string.

Example:

classNamesample

 {

static void main(String args[])

{

String s1 = "my name is mani";

int leng = s1.length();System.Console.WriteLine( "The Length of the String s1 is : " + leng );

}

}

Output: String Object Length is : 15

String Methods

Methods

Meaning

public static int Compare(string strA, string strB)

To Compare two specified string objects

public static int Compare(string str1, string str2, bool caseignore )

To Compare two specified strings and also ignores case

public static string Concat(string str1, string str2)

Concatenates two string objects.

public static string Concat(string str, string str1, string str2)

Concatenates three string objects.

public static string Concat(string str1, string str2, string str3, string str4)

Concatenates four string objects.

public bool Contains(string value)

To check the specified String object occurs within this string.

public static string Copy(string str)

To Create a new String object with the same value

public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)

To Copy a specified number of characters from a given position of the String object to a specified position in an array

public bool EndsWith(string value)

To check whether the end of the string matches the given string.

public bool Equals(string value)

To check whether the current String and the given String  have the same value.

public static bool Equals(string a, string b)

To check whether two specified String have the same value.

public static string Format(string format, Object arg0)

It places the format items in a given string with the string depiction of a given object.

public int IndexOf(char value)

Returns index of the first occurrence of the given character in the current string.

public int IndexOf(string value)

Returns index of the first occurrence of the given string

public int IndexOf(char value, int startIndex)

Returns index of the first occurrence of the specified character from the specified character position.

public int IndexOf(string value, int startIndex)

Returns index of the first occurrence of the specified string from the specified character position.

public int IndexOfAny(char[] anyOf)

Returns index of the first occurrence of any character in a given array of characters.

public int IndexOfAny(char[] anyOf, int startIndex)

Returns index of the first occurrence of any character in a given array of characters from the given character position.

public string Insert(int startIndex, string value)

Given string is inserted at a given index position

public static bool IsNullOrEmpty(string value)

Returns whether the given string is null or an empty

public static string Join(string separator, params string[] value)

Joins all the elements of a string array, using the given separator

public static string Join(string divider, string[] value, int startindex, int count)

Joins the given elements of a string array, using the given separator

public int LastIndexOf(char value)

To find the last occurrence of the specified character within the current string

public int LastIndexOf(string value)

To find the last occurrence of a specified string within the current string

public string Remove(int startIndex)

Removes all the characters beginning at a specified position the string.

public string Remove(int startIndex, int count)

Removes the given number of beginning at a specified position and returns the string.

public string Replace(char oldChar, char newChar)

Replaces all appearance of a specified Unicode character in the current string.

public string Replace(string oldValue, string newValue)

Replaces all appearance of a specified string in the current string

public string[] Split(params char[] separator)

Returns a string array that has the substrings in the current string object

public string[] Split(char[] separator, int count)

Returns a string array that has the substrings in the current string object, delimited by specified  character

public bool StartsWith(string value)

To check whether the beginning of the string matches the given string.

public char[] ToCharArray()

Returns a character array with all the characters

public char[] ToCharArray(int startIndex, int length)

Returns a character array with all the characters from the specified index to the specified length.

public string ToLower()

Converts a string to lowercase.

public string ToUpper()

Converts a string to uppercase.

public string Trim()

Removes all leading and trailing white-space characters

.