Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

I am trying to convert my VB.NET to C# (for learning purpose) and I cannot seem to find the equivalent functions for Instr() and Mid() that I had used in VB.NET to be applied to C#. Can anyone tell me what the functions are to do those two functions in C#?

 

InStr() ==> This function looks for a string within another string and returns the position where a match is found.

Mid() ==> This function function returns a specified number of characters from a string beginning at a given point.

 

Thanks in advance!

  • Administrators
Posted

Mid can be replaced with .SubString and InStr with .IndexOf

 

string s = "hello world";
int i = s.IndexOf("w");			//i=6
string s2 = s.Substring(2,4);	//s2="llo "

 

However these are not C# functions, they are intrisic to the .Net framework and you should also be using these from VB.Net rather than the legacy VB6 functions.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Thank you. Boy...there is just too much to keep up with even when I think I know VB, VB.NET is a different world.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...