Hallo
Ich weis ich bin nicht gerade der Hellste... Deshalb verzeit mir diese Frage
Ich hab schon eine Frage gestellt wie man die Zeichen einer Text Datei in Hexadezimal konvertiert. BlueCobold war so nett und hat diesen Link gepostet:
http://msdn.microsoft.com/de-de/library/…=vs.110%29.aspx
Danke noch mal! Das hat mir schon ziemlich geholfen. Mein momentaner Code sieht wie folgt aus:
|
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
24
25
26
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.IO;
namespace Hexconverter
{
class Program
{
static void Main(string[] args)
{
{
string path = @"c:\Users\luca\Desktop\How to play.txt";
// Open the file to read from.
string readText = File.ReadAllText(path);
Console.WriteLine(readText);
Console.ReadKey();
}
}
}
}
|
Nun schreibt das Programm alle Wörter in der Textdatei in der Konsolenanwendung ab oder kopiert sie (oder wie auch immer das funktioniert
![:D](wcf/images/smilies/biggrin.png.pagespeed.ce.UPFXer8Yu2.png)
). Nun ist meine Frage: Wie muss ich den Code weiter verfeinern sodass der Text in Hexadezimal erscheint?
Ist dieser Code vielleicht besser?:
|
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.IO;
namespace Hexconverter
{
class Program
{
static void Main(string[] args)
{
{
string path = @"c:\Users\luca\Desktop\How to play.txt";
// This text is added only once to the file.
if (!File.Exists(path))
{
// Create a file to write to.
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText, Encoding.UTF8);
}
// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText, Encoding.UTF8);
// Open the file to read from.
string readText = File.ReadAllText(path);
Console.WriteLine(readText);
Console.ReadKey();
}
}
}
}
|
Gefunden hab ich einen funktionierenden Codeausschnitt der wie folgt aussieht:
|
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
24
|
string input = "Hello World!";
char[] values = input.ToCharArray();
foreach (char letter in values)
{
// Get the integral value of the character.
int value = Convert.ToInt32(letter);
// Convert the decimal value to a hexadecimal value in string form.
string hexOutput = String.Format("{0:X}", value);
Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
}
/* Output:
Hexadecimal value of H is 48
Hexadecimal value of e is 65
Hexadecimal value of l is 6C
Hexadecimal value of l is 6C
Hexadecimal value of o is 6F
Hexadecimal value of is 20
Hexadecimal value of W is 57
Hexadecimal value of o is 6F
Hexadecimal value of r is 72
Hexadecimal value of l is 6C
Hexadecimal value of d is 64
Hexadecimal value of ! is 21
*/
|
Nur gibt es da ein Problem: Jeder einzelne Buchstabe bekommt eine eigene Zeile... Das ist eigentlich nicht ganz das was ich brauche. Ich will das wenn der Satz in der Textdatei aufhört, dass er dann auch in der Konsolenanwendung aufhört und eine neue Zeile beginnt.
Wäre echt dankbar über ein paar Erklärungen und nicht nur Links.
Danke Voraus!