Dear friends,
Anybody help me How could you use the Mid function in C# 2005?
Tnx
Dear friends,
Anybody help me How could you use the Mid function in C# 2005?
Tnx
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dinusha GamagePosted Mar 17, 2008, 10:59 PM
AlanPosted Mar 17, 2008, 7:18 AM
Although it's possible to reference VB.Net's Mid() function from C#, there's no need to do so when you can use the String.Substring() method instead.
For example:
string s = "This is a string";
string t = s.Substring(5, 2);
Console.WriteLine(t); // 'is'
has the same effect as:
Dim s As String = "This is a string"
Dim t As String = Mid(s, 6, 2)
Console.WriteLine(t)
The only thing to note is that Substring() uses zero-based indexing but Mid() uses one-based indexing.