How to use indexof property in C#

How do i translate this VB6 code to C#
test = InStr(1, strText, vbTab)

I tried

test  = strText.Tostring().Indexof('\t',0)  -- but did not work




pratikshahseAsked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
IndexOf returns an integer with position, not a string, just like InStr. So should be something like:

ListViewItem item = lstMfgColors.SelectedItems[I];
int pos = item.Text.Indexof("\t",0)+1;
0
 
Jaime OlivaresSoftware ArchitectCommented:
assumming test is integer and strText is a string. This should work

test  = strText.Indexof("\t")+1

0
 
pratikshahseAuthor Commented:
actually this is what i have

object item = lstMfgColors.SelectedItems[I];

string o = item.ToString().Indexof("\t",0);
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Jaime OlivaresSoftware ArchitectCommented:
Is that what you need?
Maybe some sourcecode around it would be more explanatory...
0
 
mmq2006Commented:
Could you please explain what this code does exactly:

test = InStr(1, strText, vbTab)
0
 
mmq2006Commented:
try this:
- Use a string variable type string:
string segment = str.Substring(index1,len);
where segment is a variable to store the substring,
str is the original string,
index1 is the zero-based starting position of the substring that you want to extract,
len is the number of characters you wish to extract.

This should resolve it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.