[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6924
  • Last Modified:

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




0
pratikshahse
Asked:
pratikshahse
  • 3
  • 2
1 Solution
 
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now