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!!!
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
VB/Office Guru™ (AKA: Gangsta Yoda™®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Star Wars Gangsta Rap • Reps & Rating Posts • VS.NET on Vista (New) • Multiple .NET Framework Versions (New) • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
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.
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter
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;
}
}