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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Mar 17, 2008, 3:18 AM EDT
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.
Dinusha Gamage67 reputationPosted Mar 17, 2008, 6:59 PM EDT