Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use indexof property in C#

Posted on 2007-11-16
6
Medium Priority
?
6,920 Views
Last Modified: 2013-12-17
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
Comment
Question by:pratikshahse
  • 3
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20299984
assumming test is integer and strText is a string. This should work

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

0
 

Author Comment

by:pratikshahse
ID: 20300143
actually this is what i have

object item = lstMfgColors.SelectedItems[I];

string o = item.ToString().Indexof("\t",0);
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 total points
ID: 20300214
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20302000
Is that what you need?
Maybe some sourcecode around it would be more explanatory...
0
 
LVL 1

Expert Comment

by:mmq2006
ID: 20303868
Could you please explain what this code does exactly:

test = InStr(1, strText, vbTab)
0
 
LVL 1

Expert Comment

by:mmq2006
ID: 20303909
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question