Solved

VB to C#

Posted on 2011-02-26
5
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 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