• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

Split Commandline Arguments/parameters Into Variables

Stuck on a bit of code. We are calling a program with parameters, Example: program.exe \\server\file nameoffile pdf status. Want to take each parameter separated by a space and assign it to a string variable. On this line  "string[] words = args.Split(' ');", "args" is giving me the error system.array has no definition for Split. Have not been able to get past this point.

Any help or comments are welcomed!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
    public partial class Programname : Form
        string[] args = Environment.GetCommandLineArgs();
        public Programname()

        private void OpenDrawing_Click(object sender, EventArgs e)

            string[] words = args.Split(' ');

            string docPath = words[0];
            string docFile = words[1];
            string docExt = words[2];
            string docType = words[3];
            string docStatus = words[4];


Open in new window

  • 2
1 Solution
käµfm³d 👽Commented:
Exactly. args is already a string array, which is what Split would have given you back had args simply a string (rather than an array of strings). Just index args as the system will handle the splitting of the command line for you.
Daniel_P67Author Commented:
Great thanks!!! Checked with the below code. Placed a quick text box and pasted in the info out of order, worked just like i wanted.

//string[] words = args.Split(' '); //deleted

            string docPath = args[0];
            string docFile = args[1];
            string docExt = args[2];
            string docType = args[3];
            string docStatus = args[4];

            textBox1.Text = docPath + docExt + docFile;

Open in new window

Daniel_P67Author Commented:
Explanation was good enough to help me solve the issue. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now