Solved

VB to C#

Posted on 2011-02-26
5
231 Views
Last Modified: 2012-05-11
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
Comment
Question by:avi7
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34988522
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
 

Author Comment

by:avi7
ID: 34988588
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
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34988621
Try this correction for that line
  Array1Values =  CustomerArray.Split(Convert.ToChar(",") );

Open in new window

0
 

Author Comment

by:avi7
ID: 34988707
Thanks a lot!
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34988769
Glad to help you!
Raj
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mutually exclusive checkbox in a gridview 18 41
Using MS Code on my Mac 6 45
Where to begin studying? 5 66
Round up to 100% in .NET 10 44
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now