Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C#] Write hex to file

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
131
I have hex code like the following I would like to write to a file. Can someone give me a simple example of how this is done? Thank you.

Hex Code =
PHP:
012003000058020000100000000100000000000000000001
 
Joined
Apr 27, 2009
Messages
438
Reaction score
103
Do you know the Hex Code you want to write to a file or are you pulling it from somewhere?

If you know the Hex you want to write to a file something like

Code:
using System.IO;

class Program
{
    static void Main()
    {
	using (StreamWriter writer =
	    new StreamWriter("hex.txt"))
	{
	    writer.Write("012003000058020000100000000100000000000000000001");
	}
    }
}

I'm assuming your problem is more complex than this so maybe explain a little more?
 
Last edited:
Joined
Apr 27, 2009
Messages
438
Reaction score
103
Pulled from MSDN I know it's not a string but shouldn't matter

Code:
class WriteTextFile
{
    static void Main()
    {
        // Example #2: Write one string to a text file.
        string text = "Insert hex";
        // WriteAllText creates a file, writes the specified string to the file,
        // and then closes the file.    You do NOT need to call Flush() or Close().
        System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\Hex.txt", text);
 
Watching from above
Legend
Joined
Apr 9, 2004
Messages
3,828
Reaction score
752
Are you sure you want to write a hex code as a string into a file? Because if that's what you really want then I imagine you would've asked for how to write any text into a file. A more useful and therefore probable case is that you want to convert the hex string into a binary string and write that into a binary file at a specific location.
 
Watching from above
Legend
Joined
Apr 9, 2004
Messages
3,828
Reaction score
752
.. and in that case, this Q&A should take you a little closer to what you want :)



And then this method is probably what will do the trick of writing the byte array into a file at a given position

 
Back
Top