Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 107,664 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,067 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



string to string[]

 
Reply to this topicStart new topic

string to string[], Is there any command to do this or do I need a custom function

SpiderSpartan
post 5 Aug, 2008 - 10:37 AM
Post #1


D.I.C Head

**
Joined: 6 Feb, 2008
Posts: 59



Thanked 3 times
My Contributions


I need to take a Console.ReadLine() input and put it in the for of a string[] to work with existing code. Is there a command or simple way to do this, or will I need a custom function? Thanks.
User is offlineProfile CardPM

Go to the top of the page


jayman9
post 5 Aug, 2008 - 11:00 AM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,300



Thanked 21 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Can you provide an example of the input?

You could use the Split function, depending on the input you are getting from the user.
User is offlineProfile CardPM

Go to the top of the page

SpiderSpartan
post 5 Aug, 2008 - 11:28 AM
Post #3


D.I.C Head

**
Joined: 6 Feb, 2008
Posts: 59



Thanked 3 times
My Contributions


Here is the code I was running. When I try to run this I get an error "Index was outside the bounds of the array." on the line "args[0] = Console.ReadLine();"

CODE


static void Main(string[] args)
        {
            while (args.Length < 1 || args[0] == null)
            {
                Console.WriteLine(@"No file passed. Pass model file path and name. (EX: VCChecklist 'C:\Model.igv'). Please enter a correct path or type 'Exit' to cancel.");
                args[0] = Console.ReadLine();
                if (File.Exists(args[0]))
                {
                    CompileChecklist(args[0]);
                    return;
                }
                else
                {
                    Console.WriteLine("File '" + args[0] + "' could not be found.");
                    args[0] = null;
                }

            }
             return;
        }


I was able to get around this issue by setting
CODE
args = new string[1];
and then using
CODE
args[0] = Console.ReadLine();


This post has been edited by SpiderSpartan: 5 Aug, 2008 - 11:29 AM
User is offlineProfile CardPM

Go to the top of the page

zakary
post 5 Aug, 2008 - 11:32 AM
Post #4


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 370



Thanked 4 times

Dream Kudos: 175
My Contributions


try this in your main
csharp

string FileDirPath = string.Empty;
if (args.Length == 0)
{
Console.WriteLine(@"No file passed. Pass model file path and name. (EX: VCChecklist 'C:\Model.igv'). Please enter a correct path or type 'Exit' to cancel.");
}
else
{
for (int i = 0; i < args.Length; i++)
{
switch (args[i].ToLower())
{
case "-file":
if (++i != args.Length)
{
FileDirPath = args[i];
}
break;
default:
System.Console.WriteLine(
"Unknown parameter (" + args[i] + ") passed into the application.");
break;
}
}
}


This post has been edited by zakary: 5 Aug, 2008 - 11:40 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 10:38PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month