C# equivalent of VB6 Left

M

Mike P

What is the C# equivalent of Left in VB6? I'm not sure how to translate
this line of code :

strResultCode = Left$(txtOutput, InStr(1, txtOutput, ",") - 1)


Any help would be really appreciated.


Cheers,

Mike
 
B

Ben Dewey

Use:
string.Substring(start, length);

ie:
string something = "this is,my text";
string newString = something.Substring(0, something.IndexOf(","));
 
D

Dan Bass

I presume you're looking to take all the string characters to the left of
the ","?
SubString does quite well here...

int CommaIndex = Output.IndexOf ( ',' );
if ( CommaIndex >= 0 )
{
// comma found
ResultString = Output.SubString ( 0, CommaIndex );
}
else
{
// for a case with no ,
ResultString = Output; // or ""?
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top