Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error while initializing two-dimensional array

Posted on 2008-10-19
2
Medium Priority
?
628 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 150 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

705 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