cSharp learning course

Length returns the length of the string.
IndexOf(value) returns the index of the first occurrence of the value within the string.
Insert(index, value) inserts the value into the string starting from the specified index.
Remove(index) removes all characters in the string after the specified index.
Replace(oldValue, newValue) replaces the specified value in the string.
Substring(index, length) returns a substring of the specified length, starting from the specified index. If length is not specified, the operation continues to the end of the string.
Contains(value) returns true if the string contains the specified value.

 

using System;

public class Program
{
public static void Main()
{
string a = "My text";
Console.WriteLine(a.Length);
Console.WriteLine(a.IndexOf('t'));

a = a.Replace("M","m");

a = a.Insert(0, "This is ");
Console.WriteLine(a);

a = a.Replace("This is", "This's");
Console.WriteLine(a);


if(a.Contains("text"))
Console.WriteLine("great, the text contains \"text\"");


a = a.Substring(0,6);
Console.WriteLine(a);


a = a.Remove(4);
Console.WriteLine(a);

a = a.Insert(4, " the end");
Console.WriteLine(a);

}
}

 

Appendix

foreach (int k in a)
{
Console.WriteLine(k);
}

for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl