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

Join 136,157 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,126 people online right now. Registration is fast and FREE... Join Now!




Dealing with text and args

 
Reply to this topicStart new topic

Dealing with text and args, Making the program recognize every text

inf_f
23 Dec, 2007 - 01:38 AM
Post #1

New D.I.C Head
*

Joined: 23 Dec, 2007
Posts: 2


My Contributions
Hi everyone smile.gif
I am having this question almost for long time , and so when i went to learn c# (which was before few days) i really want to use it as my primary programming language and so i want to take it into serous level (you may probably see my n00by questions asked here too much)

Ok , let's assume this
When we get a text like :
CODE
Devices founds:    
    CDROM location = /dev/scd01 , mounted at /media/cdrom
    HardDisk Location /dev/sda1 , mounted at /media/harddisk

how i can deal with that? , i want to make the program to know that text as something we could use it (array or any other things that c# support) like we have got a 2 devices found and they are CDROM and HardDisk each of them got their own properties.


if i wasn't clear in my previous example i hope this clear it a bit
Example:
passing args into the program when it start up => app.exe -o file.txt -w Text to be written at the end of the text
here i want the program to recognize the file name "file.txt" which comes after -o , and to know that everythings after -w should be written into the file.

I hope someone could help me with this or at lest giving me reference or something to read it
and thanks in advance smile.gif
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Dealing With Text And Args
26 Dec, 2007 - 12:57 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
So you're basically trying to make a program that appends text into a specified text file?
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Dealing With Text And Args
26 Dec, 2007 - 03:45 AM
Post #3

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,131



Thanked: 16 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
Maybe something like this? (Built with a C# Console application).

CODE

static void Main(string[] args)
{
    // Check that the cmd arguments aren't above or below four.
    if (args.Length != 4 || args[0] != "-o" || args[2] != "-w")
    {
        Console.WriteLine("Invalid arguments.");
        return; // Exit the program.
    }

    // Just to make it easier to follow.
    string filePath = args[1];
    string textToAppend = args[3];

    try {
        // Write the text to append to the file.
        System.IO.File.AppendAllText(filePath, textToAppend);
    }

    catch (Exception ex)
    {
        // Display error if any.
        Console.WriteLine("Couldn't write to file: Error: {0}", ex.Message);
    }            
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 11:21PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month