Click here to Skip to main content
15,887,446 members
Home / Discussions / C#
   

C#

 
AnswerRe: FTP Multiple Files With Progress Pin
Bernhard Hiller20-Sep-16 20:47
Bernhard Hiller20-Sep-16 20:47 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:13
professionalKevin Marois21-Sep-16 9:13 
GeneralRe: FTP Multiple Files With Progress Pin
Bernhard Hiller21-Sep-16 20:54
Bernhard Hiller21-Sep-16 20:54 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois22-Sep-16 6:07
professionalKevin Marois22-Sep-16 6:07 
AnswerRe: FTP Multiple Files With Progress Pin
Peter_in_278022-Sep-16 15:07
professionalPeter_in_278022-Sep-16 15:07 
SuggestionRe: FTP Multiple Files With Progress Pin
Richard Deeming21-Sep-16 2:51
mveRichard Deeming21-Sep-16 2:51 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:19
professionalKevin Marois21-Sep-16 9:19 
QuestionIndexOutOfRange Exception When Using Multi Dimensional Array Pin
MadDashCoder20-Sep-16 6:07
MadDashCoder20-Sep-16 6:07 
I am trying to extract the IDs or Names from a string and insert them in the first cell of each row and put the rest of the string in the remaining cells of each row.

For instance if I have the following string
{ID:AA, Make:ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name:XD, Make:DHS, Year:2006}


The data in the array will look like the following after extracting the IDs or Names, inserting them into the first cell of each row, then putting the rest of the string in the remaining cell of each row. The vertical bars represent the cells of the array.
|ID:AA|Make:ABC, Year:1995|
|ID:BB|Make:BBC, Year:2000|
|ID:XD|Make:DHS, Year:2006|

I have tried the following but its giving me the IndexOutOfRange exception.

C#
string testString = "{ID:AA, Make:ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name:XD, Make:DHS, Year:2006}";
string[] outerArray = Regex.Split(testString, "},{");
string[,] innerArray = new string[2, outerArray.Length];
string idPattern = "^(ID)(.*?),";
string namePattern = "^(Class)(.*?),";

for (int i = 0; i < outerArray.Length; i++)
{
    outerArray[i] = outerArray[i].Replace("{", "").Replace("}", "");
    for (int y = 0; y < innerArray.Length; y++)
    {
        for (int x = 0; x < innerArray.Length; x++)
        {
            var matched_ID = Regex.Match(outerArray[i], idPattern);
            var matched_Name = Regex.Match(outerArray[i], namePattern);

            if (matched_ID.Success)
            {
                innerArray[x, y] = (matched_ID.Value).Replace(",", "");
            }
            else if (matched_Name.Success)
            {
                innerArray[x, y] = (matched_Name.Value).Replace(",", "");
            }

            if (outerArray[i].Length > 0 && !outerArray[i].Contains("ID:") && !outerArray[i].Contains("Name:"))
            {
                innerArray[x, y] = outerArray[i];
            }
            outerArray[i] = outerArray[i].Replace(matched_ID.Value, "");
            outerArray[i] = outerArray[i].Replace(matched_Name.Value, "");
        }
    }
}


modified 20-Sep-16 12:47pm.

AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
OriginalGriff20-Sep-16 6:18
mveOriginalGriff20-Sep-16 6:18 
GeneralRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
MadDashCoder20-Sep-16 6:40
MadDashCoder20-Sep-16 6:40 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
ZurdoDev20-Sep-16 7:40
professionalZurdoDev20-Sep-16 7:40 
GeneralRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
OriginalGriff20-Sep-16 8:03
mveOriginalGriff20-Sep-16 8:03 
SuggestionRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
Richard Deeming20-Sep-16 8:16
mveRichard Deeming20-Sep-16 8:16 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
Gerry Schmitz20-Sep-16 9:15
mveGerry Schmitz20-Sep-16 9:15 
Questionforms and SSO login Pin
V.20-Sep-16 1:19
professionalV.20-Sep-16 1:19 
QuestionSSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4119-Sep-16 9:20
David_4119-Sep-16 9:20 
AnswerRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz19-Sep-16 10:58
mveGerry Schmitz19-Sep-16 10:58 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4119-Sep-16 11:13
David_4119-Sep-16 11:13 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz19-Sep-16 18:05
mveGerry Schmitz19-Sep-16 18:05 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 5:19
David_4120-Sep-16 5:19 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 5:31
mveGerry Schmitz20-Sep-16 5:31 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 7:53
David_4120-Sep-16 7:53 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 8:34
mveGerry Schmitz20-Sep-16 8:34 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 8:39
David_4120-Sep-16 8:39 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 9:43
mveGerry Schmitz20-Sep-16 9:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.