• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

Conversion question

Hi,
I have a following cod in VB and I am trying to convert it to C#... Thanks!

  WhereClause = " where " & Strings.Mid(WhereClause, 6)

  WhereClause = " where " + WhereClause.Substring(5, WhereClause.Length);

I am getting the following error for C# part:
ArgumentOutOfRangeException was unhandled by user code
Index and length must refer to a location within the string.
Parameter name: length
0
avi7
Asked:
avi7
3 Solutions
 
sshah254Commented:
shouldn't it be whereclause.length - 5?

Ss
0
 
avi7Author Commented:
I am getting this:
Error Operator '-' cannot be applied to operands of type 'string' and 'int'
0
 
Arthur_WoodCommented:
shouldn't you be using:

WhereClause = " where " + WhereClause.Substring(5, WhereClause.Length - 5);

AW
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Kalpesh ChhatralaSoftware ConsultantCommented:
Paste your Sample code here
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can just do:

    WhereClause = " where " & WhereClause.Substring(5)

*But this assumes that WhereClause has at least six characters in it.

To be safe:

    if (WhereClause.Length >= 6)
    {
        WhereClause = " where " & WhereClause.Substring(5)
    }
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*I forgot the semicolons ";" on the ends of the lines though!

    if (WhereClause.Length >= 6)
    {
        WhereClause = " where " & WhereClause.Substring(5);
    }
0
 
avi7Author Commented:
Thanks, let me try this...
0
 
avi7Author Commented:
Thanks! It is working :)
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.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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