Click here to Skip to main content
15,860,972 members
Home / Discussions / C#
   

C#

 
AnswerRe: Can't multiply... Pin
Luc Pattyn16-Dec-09 11:07
sitebuilderLuc Pattyn16-Dec-09 11:07 
GeneralRe: Can't multiply... Pin
o m n i16-Dec-09 11:11
o m n i16-Dec-09 11:11 
GeneralRe: Can't multiply... Pin
Luc Pattyn16-Dec-09 11:21
sitebuilderLuc Pattyn16-Dec-09 11:21 
GeneralRe: Can't multiply... Pin
o m n i16-Dec-09 12:57
o m n i16-Dec-09 12:57 
GeneralRe: Can't multiply... Pin
Luc Pattyn16-Dec-09 13:15
sitebuilderLuc Pattyn16-Dec-09 13:15 
QuestionString Placeholder/Templating Question Pin
Member 158975816-Dec-09 9:32
Member 158975816-Dec-09 9:32 
AnswerRe: String Placeholder/Templating Question Pin
Ian Shlasko16-Dec-09 10:47
Ian Shlasko16-Dec-09 10:47 
AnswerRe: String Placeholder/Templating Question Pin
PIEBALDconsult17-Dec-09 8:11
mvePIEBALDconsult17-Dec-09 8:11 
Here's a little Extension Method to do that. It uses a Regular Expression to find the templates, formats the value, and performs replacements.

I assumed you wanted to SPACE-pad the value, but you could change it.

public static class Junk
{
    private static readonly System.Text.RegularExpressions.Regex reg ;

    private static readonly System.Collections.Generic.Dictionary<string,string> dic ;

    static Junk
    (
    )
    {
        reg = new System.Text.RegularExpressions.Regex
        (
            "(?'Template'(?'Pattern'#+)(?:(?'Fill'0+)|(?'Fill'9+)){0,1})"
        ) ;

        dic = new System.Collections.Generic.Dictionary<string,string>() ;

        return ;
    }

    public static string
    ApplyTemplate
    (
        this int Value
    ,
        string   Template
    )
    {
        lock ( dic )
        {
            foreach
            (
                System.Text.RegularExpressions.Match mat
            in
                reg.Matches ( Template )
            )
            {
                string tem = mat.Groups [ "Template" ].Value ;

                if ( !dic.ContainsKey ( tem ) )
                {
                    string pat = mat.Groups [ "Pattern" ].Value ;
                    string fil = mat.Groups [ "Fill"    ].Value ;

                    string temp = Value.ToString().PadLeft ( pat.Length + fil.Length ) ;

                    temp = temp.Substring ( 0 , temp.Length - fil.Length ) + fil ;

                    dic [ tem ] = temp ;
                }
            }

            foreach
            (
                System.Collections.Generic.KeyValuePair<string,string> repl
            in
                dic
            )
            {
                Template = Template.Replace ( repl.Key , repl.Value ) ;
            }

            dic.Clear() ;
        }

        return ( Template ) ;
    }
}

Questionsimple PAssword Policy Pin
THE SK16-Dec-09 9:16
THE SK16-Dec-09 9:16 
AnswerRe: simple PAssword Policy Pin
Luc Pattyn16-Dec-09 9:40
sitebuilderLuc Pattyn16-Dec-09 9:40 
GeneralRe: simple PAssword Policy Pin
THE SK16-Dec-09 9:55
THE SK16-Dec-09 9:55 
AnswerRe: simple PAssword Policy Pin
#realJSOP16-Dec-09 10:03
mve#realJSOP16-Dec-09 10:03 
GeneralRe: simple PAssword Policy Pin
Eddy Vluggen16-Dec-09 10:52
professionalEddy Vluggen16-Dec-09 10:52 
QuestionLooking to Learn Programming better Need help please. Pin
Extremeshannon16-Dec-09 8:05
Extremeshannon16-Dec-09 8:05 
AnswerRe: Looking to Learn Programming better Need help please. Pin
OriginalGriff16-Dec-09 8:22
mveOriginalGriff16-Dec-09 8:22 
AnswerRe: Looking to Learn Programming better Need help please. Pin
#realJSOP16-Dec-09 8:59
mve#realJSOP16-Dec-09 8:59 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Pete O'Hanlon16-Dec-09 9:02
subeditorPete O'Hanlon16-Dec-09 9:02 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Luc Pattyn16-Dec-09 9:43
sitebuilderLuc Pattyn16-Dec-09 9:43 
GeneralRe: Looking to Learn Programming better Need help please. Pin
PIEBALDconsult16-Dec-09 10:35
mvePIEBALDconsult16-Dec-09 10:35 
GeneralRe: Looking to Learn Programming better Need help please. Pin
Luc Pattyn16-Dec-09 11:02
sitebuilderLuc Pattyn16-Dec-09 11:02 
GeneralRe: Looking to Learn Programming better Need help please. Pin
PIEBALDconsult16-Dec-09 11:50
mvePIEBALDconsult16-Dec-09 11:50 
AnswerRe: Looking to Learn Programming better Need help please. Pin
BillWoodruff16-Dec-09 18:17
professionalBillWoodruff16-Dec-09 18:17 
QuestionContinued Values Collection/List/Dictionary [modified] Pin
Som Shekhar16-Dec-09 7:48
Som Shekhar16-Dec-09 7:48 
AnswerRe: Continued Values Collection/List/Dictionary Pin
#realJSOP16-Dec-09 9:04
mve#realJSOP16-Dec-09 9:04 
GeneralRe: Continued Values Collection/List/Dictionary Pin
Som Shekhar16-Dec-09 19:16
Som Shekhar16-Dec-09 19:16 

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.