Substring
In this chapter you will learn:
Get the substring from the start of a string
SubString returns the substring from the current. Specify only the start position
using System;//from ja v a 2 s . c om
class Sample
{
public static void Main()
{
string s = "java2s.com";
Console.WriteLine(s.Substring(2));
}
}
The output:
Get the sub string from the middle
Specify both the start and end
using System;/*from j av a 2s .com*/
class Sample
{
public static void Main()
{
string s = "java2s.com";
Console.WriteLine(s.Substring(2, 3));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- How to escape characters in String
- Character escape sequence: \0
- Escape sequences in strings: embed quotes
- Escape sequences in strings: \t (tab)
- Escape sequences in strings: \n (new line)
Home » C# Tutorial » String