Solved

Error while initializing two-dimensional array

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# Reverse int in fast ways 6 27
cs.Designer Issue(2) 2 14
fomat Json objects 6 15
Iterate a dictionnary to change values 4 23
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

19 Experts available now in Live!

Get 1:1 Help Now