[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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