Solved

Error while initializing two-dimensional array

Posted on 2008-10-19
2
623 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

786 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