Solved

Error while initializing two-dimensional array

Posted on 2008-10-19
2
626 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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!
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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