Click here to Skip to main content
15,888,113 members
Home / Discussions / C#
   

C#

 
Questionsplitting values randomly - C# Pin
flower_t21-Sep-09 1:05
flower_t21-Sep-09 1:05 
AnswerRe: splitting values randomly - C# [modified] Pin
Calla21-Sep-09 1:29
Calla21-Sep-09 1:29 
AnswerRe: splitting values randomly - C# Pin
OriginalGriff21-Sep-09 2:46
mveOriginalGriff21-Sep-09 2:46 
AnswerRe: splitting values randomly - C# Pin
flower_t21-Sep-09 2:56
flower_t21-Sep-09 2:56 
GeneralRe: splitting values randomly - C# Pin
harold aptroot21-Sep-09 3:38
harold aptroot21-Sep-09 3:38 
GeneralRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 7:39
mvePIEBALDconsult21-Sep-09 7:39 
AnswerRe: splitting values randomly - C# Pin
Luc Pattyn21-Sep-09 4:10
sitebuilderLuc Pattyn21-Sep-09 4:10 
AnswerRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 4:57
mvePIEBALDconsult21-Sep-09 4:57 
Mightn't a Regular Expression help?


Edit:

As long as no delimiters are repeated, you can use a Regex to determine the order of the delimiters, then build another Regex to extract the data.

namespace Template
{
    public static class Template
    {
        private static readonly System.Text.RegularExpressions.Regex reg ;
        private static readonly System.Collections.Generic.Dictionary<string,string> dic ;
 
        static Template
        (
        )
        {
            reg = new System.Text.RegularExpressions.Regex
            (
                "(\\*|/|\\(|:|\\?|!@|!\\+|\\+|@)"
            ) ;
 
            dic = new System.Collections.Generic.Dictionary<string,string>() ;
 
            dic [ "*"  ] = "(?:\\*(?'Asterisk'.+?))" ;
            dic [ "/"  ] = "(?:/(?'Slash'.+?))"   ;
            dic [ "("  ] = "(?:\\((?'LeftParenthesis'.+?))" ;
            dic [ ":"  ] = "(?::(?'Colon'.+?))"   ;
            dic [ "?"  ] = "(?:\\?(?'QuestionMark'.+?))" ;
            dic [ "!@" ] = "(?:!@(?'ExclamationAt'.+?))" ;
            dic [ "!+" ] = "(?:!\\+(?'ExclamationPlus'.+?))" ;
            dic [ "+"  ] = "(?:\\+(?'Plus'.+?))" ;
            dic [ "@"  ] = "(?:@(?'At'.+?))"   ;
 
            return ;
        }
 
        [System.STAThreadAttribute()]
        public static int
        Main
        (
            string[] args
        )
        {
            int result = 0 ;
 
            try
            {
                System.Text.StringBuilder sb = 
                    new System.Text.StringBuilder ( "^" ) ;
 
                foreach
                (
                    System.Text.RegularExpressions.Match mat
                in
                    reg.Matches ( args [ 0 ] )
                )
                {
                    sb.Append ( dic [ mat.Value ] ) ;
                }
 
                sb.Append ( "$" ) ;
 
                System.Text.RegularExpressions.Regex temp =
                    new System.Text.RegularExpressions.Regex
                    (
                        sb.ToString()
                    ) ;
 
                foreach
                (
                    System.Text.RegularExpressions.Match mat
                in
                    temp.Matches ( args [ 0 ] )
                )
                {
                    foreach ( string gro in temp.GetGroupNames() )
                    {
                        System.Console.WriteLine ( "{0} = {1}" , gro , mat.Groups [ gro ].Value ) ;
                    }
                }
            }
            catch ( System.Exception err )
            {
                while ( err != null )
                {
                    System.Console.WriteLine ( err ) ;
 
                    err = err.InnerException ;
                }
            }
 
            return ( result ) ;
        }
    }
}

GeneralRe: splitting values randomly - C# Pin
Luc Pattyn21-Sep-09 5:40
sitebuilderLuc Pattyn21-Sep-09 5:40 
GeneralRe: splitting values randomly - C# Pin
OriginalGriff21-Sep-09 5:52
mveOriginalGriff21-Sep-09 5:52 
GeneralRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 6:11
mvePIEBALDconsult21-Sep-09 6:11 
GeneralRe: splitting values randomly - C# [modified] Pin
PIEBALDconsult21-Sep-09 7:22
mvePIEBALDconsult21-Sep-09 7:22 
GeneralRe: splitting values randomly - C# Pin
Luc Pattyn21-Sep-09 7:50
sitebuilderLuc Pattyn21-Sep-09 7:50 
GeneralRe: splitting values randomly - C# Pin
OriginalGriff21-Sep-09 5:48
mveOriginalGriff21-Sep-09 5:48 
GeneralRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 7:42
mvePIEBALDconsult21-Sep-09 7:42 
AnswerRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 7:50
mvePIEBALDconsult21-Sep-09 7:50 
QuestionMicrosoft Document Explorer is driving me CRAZY Pin
Axonn Echysttas21-Sep-09 0:07
Axonn Echysttas21-Sep-09 0:07 
AnswerRe: Microsoft Document Explorer is driving me CRAZY Pin
Alan N21-Sep-09 1:43
Alan N21-Sep-09 1:43 
GeneralRe: Microsoft Document Explorer is driving me CRAZY Pin
Axonn Echysttas21-Sep-09 1:46
Axonn Echysttas21-Sep-09 1:46 
QuestionUsing the pdb file after release crash on customer machine running my c# executable [modified] Pin
w.hooper20-Sep-09 22:31
w.hooper20-Sep-09 22:31 
AnswerRe: Using the pdb file after release crash on customer machine running my c# executable Pin
Alan N20-Sep-09 22:57
Alan N20-Sep-09 22:57 
GeneralRe: Using the pdb file after release crash on customer machine running my c# executable Pin
w.hooper20-Sep-09 23:00
w.hooper20-Sep-09 23:00 
GeneralRe: Using the pdb file after release crash on customer machine running my c# executable Pin
Simon P Stevens20-Sep-09 23:08
Simon P Stevens20-Sep-09 23:08 
GeneralRe: Using the pdb file after release crash on customer machine running my c# executable Pin
w.hooper20-Sep-09 23:21
w.hooper20-Sep-09 23:21 
GeneralRe: Using the pdb file after release crash on customer machine running my c# executable [modified] Pin
w.hooper20-Sep-09 23:54
w.hooper20-Sep-09 23:54 

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.