Autor Beitrag
tomycat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 26.04.23 18:16 
hallo,
was muss ich ändern, dass ich einen ganzen Satz als ein Argument übernommen wird?
z.b.
ausblenden Konsole
1:
test.exe Heute ist ein schöner Tag					


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
    static void Main(string[] args)
    {
        // Step 1: test for null.
        if (args == null)
        {
            Console.WriteLine("args is null");
        }
        else
        {
            // Step 2: print length, and loop over all arguments.
            Console.Write("args length is ");
            Console.WriteLine(args.Length);
            for (int i = 0; i < args.Length; i++)
            {
                string argument = args[i];
                Console.Write("args index ");
                Console.Write(i); // Write index
                Console.Write(" is [");
                Console.Write(argument); // Write string
                Console.WriteLine("]");
            }
        }
    }


Moderiert von user profile iconNarses: C#-Tags hinzugefügt
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 26.04.23 18:48 
"Du mußt den Satz in Quotes setzen".
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 27.04.23 09:01 
???
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 27.04.23 09:05 
ausblenden Konsole
1:
test.exe "Heute ist ein schöner Tag"					
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 27.04.23 11:37 
thx,
aber wie kann ich den kompletten Satz in meinen String "meineEingabe" stecken.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 27.04.23 12:02 
user profile icontomycat hat folgendes geschrieben Zum zitierten Posting springen:
aber wie kann ich den kompletten Satz in meinen String "meineEingabe" stecken.
Du meinst wie du den komplett im aufgerufenen Programm bekommst?
ausblenden C#-Quelltext
1:
meineEingabe = args[0];					

Vorausgesetzt der Satz wurde auch wie user profile iconTh69 schrieb komplett im ersten Parameter übergeben.
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 27.04.23 16:15 
args[0] ist das dann "hallo",
ich will das aber den ganzen Satz.

Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Do 27.04.23 17:36 
Nein wenn du quotest ist alles in dem Quote in einem Array Element von args.

Bei einem
ausblenden C#-Quelltext
1:
test.exe "erstes Argument" "zweites argument"					

dann enthält
ausblenden Quelltext
1:
2:
args[0] = "erstes Argument"
args[1] = "zweites argument"

Beachte das jetzt nicht an dem Leerzeichen in verschiedene Argumente getrennte wurde. erstes Argument wären 2 Argumente, "erstes Argument" wäre ein Argument.

Aber vielleicht probierst du es einfach aus?

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 03.05.23 16:12 
ich verstehe war ihr meint.

Ich frage mal anders,
ich habe einen langen Satz.

meinprog.exe 1 2 3 4 5 6 7 8

Gibt es eine Möglichkeit, einfach die Eingabe als String aufzunehmen?
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 03.05.23 16:48 
-> Environment.CommandLine (inkl. Programmname/-pfad) oder
ausblenden C#-Quelltext
1:
string arguments = String.Join(" ", args);					

Aber was stört dich am Setzen der Anführungsstriche?