Solved

VB to C#

Posted on 2011-02-26
5
235 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FTP file download using c# 3 28
How come this regular expression allows "e"? 14 56
How to repeat the data 4 30
Making exceptions for ValidationAttribute 2 23
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

740 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