Author Topic: Format c# Arguments  (Read 4872 times)

AhsGrad1973

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Format c# Arguments
« on: October 06, 2011, 11:07:47 AM »
I use this macro to add the number of arguments to a String.Format, Console.WriteLine, etc in c#:

_command brief_AddFormatArguments() name_info(','VSARG2_REQUIRES_EDITORCTL)
    {
        // Ctrl+S

    typeless orig_position;

    int iI;
    int iPos;
    int iLen;
    int iParms = 0;

    boolean fTrue       = true;
    boolean fSingleLine = false;

    _str strMethod;
    _str strParms;
    _str strLine;
    _str strText;

    _save_pos2(orig_position);
    get_line(strMethod);

    iPos = lastpos(");", strMethod);

    if (iPos > 0)
        {
        fSingleLine = true;
        strLine = strMethod;
        }

    iPos = lastpos("(", strMethod);

    if (iPos > 0)
        {
        strMethod = substr(strMethod, 1, iPos);
        }
    else
        {
        iPos = pos("\"", strMethod);

        if (iPos > 0)
            {
            strMethod = substr(strMethod, 1, (iPos - 1));
            }
        }

    if (fSingleLine == false)
        {
        while (fTrue)
            {
            down();
            get_line(strText);

            if (last_char(strText) == ";")
                {
                iParms++;
                break;
                }
            else
                {
                iParms++;
                }
            }
        }
    else
        {
        iLen = length(strLine);
        iPos = pos("\",", strLine);

        if (iPos > 0)
            {
            strParms = substr(strLine, iPos, (iLen - iPos));
            STRARRAY strParams = split2array(strParms, ",");
            iParms = (strParams._length() - 1);
            }
        else
            {
            _restore_pos2(orig_position);
            return (0);
            }
        }

    _restore_pos2(orig_position);

    if (iParms > 0)
        {
        strMethod = strMethod:+"\"";

        _str strRet = _message_box("Yes = Use a space\r\nCancel = Use a comma\r\nNo = No separation.",
                                   "What do you want to use as a separator?",
                                   MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1);

        for (iI = 0; iI < iParms; iI++)
            {
            if (strRet == IDYES)
                {
                if (iI < (iParms - 1))
                    {
                    strText = "{":+iI:+"} ";
                    }
                else
                    {
                    strText = "{":+iI:+"}";
                    }
                }
            else if (strRet == IDNO)
                {
                strText = "{":+iI:+"}";
                }
            else // IDCANCEL
                {
                strText = "{":+iI:+"},";
                }

            strMethod = strMethod:+strText;
            }

        if (fSingleLine == true)
            {
            strMethod = strMethod :+ strParms :+ ";";
            }
        else
            {
            strMethod = strMethod:+"\",";
            }

        replace_line(strMethod);
        }

    return (0);
    }

lclevesy

  • Guest
Re: Format c# Arguments
« Reply #1 on: October 06, 2011, 01:57:50 PM »
@AhsGrad1973 Thank you for your submission. It is in the running for the iPad!

The winner will be announced via our Facebook page https://www.facebook.com/slickedit, Twitter page http://www.twitter.com/slickedit, and on this forum under the main SlickEdit October Macros Challenge Rules & How to Enter post http://community.slickedit.com/index.php/topic,7327.0.html on November 7, 2011.

lclevesy

  • Guest
Re: Format c# Arguments
« Reply #2 on: November 01, 2011, 03:15:25 PM »
We'll be announcing the winner of the iPad 2 on November 7th. Until then, your submission has earned a SlickEdit t-shirt! Email your size and address to marketing@slickedit.com to receive one.