Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello, I have a C# file that contains 591 5-digit hexadecimal numbers in the format '0x?????', and I wish to replace them with their number plus a set hexadecimal number. How can I do that, even if I have to download new software? I really do not wish to type out the exact values by hand, as that would take days. Thanks in advance.

What I have tried:

I have tried figuring it out using the Notepad++ Python Script plugin, but it appears that it does not support exactly what I want to do, judging from the documentation alone.
Posted
Updated 22-Feb-24 9:22am

Okay, I am seriously facepalming right now. Easiest solution ever. Just add the value directly to every single result in Notepad++:

Find: (0x[0-9A-F]{5});

Replace: \1 + 0x617A0;

I have no idea why I was trying to edit the numbers themselves when I could simply add to them directly in the source file... Yeah, epic facepalm moment.
 
Share this answer
 
Comments
OriginalGriff 23-Feb-24 1:24am    
Erm ... that doesn't do what you originally asked for: it adds two text strings.
So if the file contained:
0x00000;
0x10000;
0x11000;
The resulting file contains this:
0x00000 + 0x617A0;
0x10000 + 0x617A0;
0x11000 + 0x617A0;
From your original description I expected you wanted this:
0x617A0;
0x717A0;
0x727A0;
Either you need to be a lot more specific when you ask a question, or your solution doesn't work.
Maq47 23-Feb-24 16:42pm    
I never said that the file contained ONLY those hex values, and I also said that it is a C# file; in other words, code. This fact alone makes the fact that it isn't only hex values self-explanatory. Here is just one line of the code with function names changed for privacy:

br.position = 0x3422C;

This line is using the BinaryReader function (called as br) to seek to 0x3422C. The project is for a binary file editor for a specific file. All lines that have hexadecimal numbers are lines that define offsets within the binary file.
I don't know of any tools that will do this, the problem being the addition of a number to another in the replacement value.

You will probably have to write your own tool to do this. This is mostly going to be reading a text file and string manipulation so it shouldn't be too difficult to do.
 
Share this answer
 
Comments
George Swan 22-Feb-24 17:36pm    
Isn't this ok?
long res= Convert.ToInt64("0Xfffff", 16);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900