-
Aug 14th, 2006, 03:58 AM
#1
Thread Starter
Fanatic Member
Mid function in c#.net or equivalent
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!!!
-
Aug 14th, 2006, 04:06 AM
#2
Re: Mid function in c#.net or equivalent
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 (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • 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 i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Aug 14th, 2006, 04:25 PM
#3
Re: Mid function in c#.net or equivalent
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.
-
Aug 19th, 2008, 12:43 PM
#4
New Member
Re: Mid function in c#.net or equivalent
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;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|