Solved

Error while initializing two-dimensional array

Posted on 2008-10-19
2
621 Views
Last Modified: 2012-05-05
In the following code I attempted to initialize a two-dimensional string array. I want to initialize it with blank spaces. It is giving error: "Wrong number of indices in []". Please also correct the return type.
public static string[] StripOffSalt(string encryptedString)

    {

        string[,] SplittedArray =  new string[,];

 

        SplittedArray[0] = encryptedString.Substring(0, 11).ToString(); //Salt

        SplittedArray[1] = encryptedString.Substring(12);   //Original Encrypted String

 

    }

Open in new window

0
Comment
Question by:rpkhare
  • 2
2 Comments
 
LVL 16

Accepted Solution

by:
CuteBug earned 50 total points
ID: 22755681
It should be
public static string[] StripOffSalt(string encryptedString)

{

    string[] SplittedArray = new string[2];
 

    SplittedArray[0] = encryptedString.Substring(0, 11).ToString(); //Salt

    SplittedArray[1] = encryptedString.Substring(12);   //Original Encrypted String
 

    return SplittedArray;

}

Open in new window

0
 
LVL 16

Expert Comment

by:CuteBug
ID: 22755687
The above code will resolve the error.
But, since you wanted a two dimensional array it should be
public static string[,] StripOffSalt(string encryptedString)

{

    // you should specify the size of the array you want to create.

    // here i have created an array having two rows and 1 columns

    string[,] SplittedArray = new string[2,1];
 

    SplittedArray[0,0] = encryptedString.Substring(0, 11).ToString(); //Salt

    SplittedArray[1,0] = encryptedString.Substring(12);   //Original Encrypted String
 

    return SplittedArray;

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

16 Experts available now in Live!

Get 1:1 Help Now