CoderSource.net
Search
Re: InStr function equivalent in Visual C#.NET
Started by Programmable at 01-30-2006 12:29 PM. Topic has 2 replies.

Print Search « Previous Thread Next Thread »
   01-30-2006, 12:29 PM
Programmable is not online. Last active: 1/31/2006 1:00:41 PM Programmable

Top 25 Posts
Joined on 01-30-2006
Posts 2
Hmm [^o)] InStr function equivalent in Visual C#.NET

I recently moved from VB6 to Visual C#.NET and need to know how I can access the functionality of VB's InStr (InString) function and also the Left, Mid, and Right functions.
For example, how can I do in C# what the following VB code does in separating a First name and Last name in a string in order to repopulate text controls on the form with the names separated?

Dim nPos As Integer 'Used in separating the values of first,last names based on the location of a 'space' character.

Dim strFullName As String 'Contains the person's complete name being retrieved.

'Begin by separating the First name from the Last name in the RecordSet
'and write their values back to their respective screen controls

nPos = InStr(1, strFullName, " ", vbTextCompare)
  If nPos > 0 Then
    frmMain.txtFirstname = Left(strFullName, nPos - 1)
    frmMain.txtLastname = Right(strFullName, Len(strFullName) - (nPos - 1))
    frmMain.txtLastname = Trim$(Right(strFullName, Len(strFullName) - nPos))
  End If

I would also like to know how to use an equivalent of VB's Left,Mid,Right string functions in C#. Thank you.
Hmm [^o)]


   Report 
   01-31-2006, 1:15 AM
admin is not online. Last active: 9/20/2008 12:10:49 AM admin

Top 10 Posts
Joined on 06-18-2005
Posts 17
Re: InStr function equivalent in Visual C#.NET
You can use the IndexOf function to get the position of a particular character.

And the Substring function for doing your other operations.

HTH


   Report 
   01-31-2006, 8:02 AM
Programmable is not online. Last active: 1/31/2006 1:00:41 PM Programmable

Top 25 Posts
Joined on 01-30-2006
Posts 2
Re: InStr function equivalent in Visual C#.NET
Thank you for your suggestion. I will give it a try.
   Report 
Codersource.Net » Programming » C# Programming » Re: InStr function equivalent in Visual C#.NET

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us