Solved

Error while initializing two-dimensional array

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

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