is there any function in C#.net that work the same as Mid function in VB? or is there any function that work the same as MID? thanks in advance!!!
Printable View
is there any function in C#.net that work the same as Mid function in VB? or is there any function that work the same as MID? thanks in advance!!!
Yes, its called the .Substring method of your string variable or .Text property of some control.
VB Code:
Dim strIP As String Dim strStart As Integer Dim strEnd As Integer Dim strString As String = "FRQ [ 859.3125]" strStart = strString.IndexOf("[") + 1 strEnd = strString.LastIndexOf("]") - 1 strIP = strString.Substring(strStart, strEnd - strStart) MessageBox.Show(strIP.Trim) '859.3125
As RobDob pointed out, the Mid function equivalent is easy in .NET, but if you were thinking of the Mid statement (e.g., Mid(x, 2, 3) = "abc"), that is *extremely complex* to generalize to a pure .NET solution.
For example:
Mid(x, 2) = "abc"
is equivalent to:
x = x.PadRight(x.Length + ("abc").Length).Remove(1, ("abc").Length).Insert(1, "abc").Substring(0, x.Length);
You see my point - you would obviously want to write your own Mid statement.
There is none, but it is quite simple to write one using Substring
public static class strMid
{
public static string Mid(string s, int a, int b)
{
string temp = s.Substring(a - 1, b);
return temp;
}
}