using System;
class Program
{
static void Main(string[] args)
{
string str1 = "133woot7";
string str2 = str1.Remove(3, 4);
Console.WriteLine(str1);
Console.WriteLine(str2);
}
}
the string class contains a readonly indexer that can be used to traverse each character in it.
static void Main(string[] args)
{
var str1 = "hello world";
foreach(char c in str1)
Console.Write(c);
}
static void Main(string[] args)
{
var str1 = "hello world";
foreach(char c in str1)
Console.Write(c);
Console.WriteLine();
Console.WriteLine(str1.Length);
}
the string class also have one static readonly property that represents an empty string.
var emptystring = String.Empty;
Now if you're going to concatenate string this is where you would use the StringBuilder class.
using System;
using System.Text;
class Program
{
static void Main(string[] args)
{
string[] Names = { "Pavel", "Tomek", "Marin", "Ivan", };
StringBuilder TheBoys = new StringBuilder();
foreach (string name in Names)
TheBoys.Append(name + Environment.NewLine);
Console.WriteLine(TheBoys);
Console.Read();
}
}