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

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

VB to C#

Hi,
I have a following code that I have a few problems with… I am trying to find if where is a C# equivalent for InStr, Split and Replace methods. Thanks!

else if ((Array1.Text != "") && (Array2.Text == ""))
{    
  Array2.Text = CustomerArray;
  string[] Array1Values;

 if (InStr(CustomerArray, "ML")) <--- error
 {
       string AccountNo;
       string Amount;

       Array1Values = Split(CustomerArray, ",", -1, CompareMethod.Text); <--- error

       AccountNo = Array1Values[1].ToString();
       Amount = Array1Values[2].ToString();

         Label1.Text = "Account No:";
         Label2.Text = AccountNo;
         Label3.Text = "Amount:";

         Amount = Replace(Amount, "$", "");  <---error
         Label4.Text = Amount;
        }
 }
0
avi7
Asked:
avi7
  • 3
  • 2
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
In C#, there is some difference. This code is not completely corrected, but I believe you will get something from this
        else if ((Array1.Text != "") && (Array2.Text == ""))
        {
            Array2.Text = CustomerArray;
            string[] Array1Values;

            if ( CustomerArray.Contains("ML")) // <--- error 
            {
                string AccountNo;
                string Amount;

                Array1Values =  CustomerArray.Split("," ); // <--- error

                AccountNo = Array1Values[1].ToString();
                Amount = Array1Values[2].ToString();

                Label1.Text = "Account No:";
                Label2.Text = AccountNo;
                Label3.Text = "Amount:";

                Amount = Amount.Replace("$", "");  // <---error
                Label4.Text = Amount;
            }
        }

Open in new window

0
 
avi7Author Commented:
Thanks!
But for the following line: Array1Values =  CustomerArray.Split("," );
I still receive error message: The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
0
 
Rajkumar GsSoftware EngineerCommented:
Try this correction for that line
  Array1Values =  CustomerArray.Split(Convert.ToChar(",") );

Open in new window

0
 
avi7Author Commented:
Thanks a lot!
0
 
Rajkumar GsSoftware EngineerCommented:
Glad to help you!
Raj
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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