I want to replace all char \x02 with \x01 without switch text mode to 'hex'. But when I put \x02 and \x01 in replace
dialog and use regex mode, it can't recognize them as HEX values. How can I achieve my goal?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What doesn't work is trying to find \r or \n (\x0a and \x0d) in regex
which is probably because only one line is read in at a time (per search/replace)
which seems to be a common limitation.
What's wrong with hex mode?
I may know one thing: something is messing up my copy/paste buffering and I stroooongly suspect Notepad++ is doing it - could well be the hex plugin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> Important: The SPACE is the marker for the end of the hex number,
> so make sure you include them or the script won't validate properly.
Why SPACE? The symbol '"' must be the end of the hex number - the same as the end of the string - not SPACE!
The symbol '"' is not a valid symbol for a hex-number, so why do we need SPACE? Please change this behaviour.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did it that way because the hex number is not necessarily the only thing in the replace string.
For example:
replace ("c\xE1 t","cat")
would change all instances of cát to cat.
I could have gone with no terminating character and always assumed a 2-byte hex number, but you can also use decimal numbers by substituting "#" for "x", so in that case you can't make any assumption about the length (except that it's between 1 and 3 digits). To keep it consistent and therefore less confusing, I decided to do it this way for both decimal and hex.
Note that if the first digit in the hex number is 0, you can optionally leave it off. Also note that it only counts the first SPACE after the hex number as the terminating character. A second one would count as an actual SPACE.
You could argue that a SPACE is not the best character to terminate it, and I'm willing to change it if you can convince me that a different character would be better.
I hope that clarifies things.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But I mean this situation: "\x02 ". The SPACE is absolutely needless here because last '"' is the end of the string unambiguously. I'm sure that all users will write just "\x02" and then do not understand why it does not work (personally I will do it ;)).
Or another example: "\x02\x03\x04" - it does not need any SPACE character, are you agree with me? So, IMO, the SPACE is required just - and only - in those cases when you have a letter after your hex number (e.g. "a\x02 b\x03 c\x04\x05").
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I might modify it so that the ending space is not required if a hex or decimal number is the last thing in the string. I can see how that might be easier if you just want to translate a single character.
As for doing it after each hex number if the next one is a hex number too, I suppose it's a reasonable request but the coding on that would be a little tricky, since I would have to check for several different cases (\r, \n, \t, or \q; \\; SPACE; and normal characters) whereas right now I only have to check for a SPACE.
If you'd like to discuss it more, please start a new thread on the SimpleScript forum in the Notepad++ Plugins Project, since we've kind of hijacked this thread.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I want to replace all char \x02 with \x01 without switch text mode to 'hex'. But when I put \x02 and \x01 in replace
dialog and use regex mode, it can't recognize them as HEX values. How can I achieve my goal?
Thanks
I think it works (or it should work as you say)
What doesn't work is trying to find \r or \n (\x0a and \x0d) in regex
which is probably because only one line is read in at a time (per search/replace)
which seems to be a common limitation.
What's wrong with hex mode?
I may know one thing: something is messing up my copy/paste buffering and I stroooongly suspect Notepad++ is doing it - could well be the hex plugin
If you're still looking for a way to do it, you can do it with the SimpleScript plugin.
The script is simply:
replace("\x02 ","\x01 ")
Important: The SPACE is the marker for the end of the hex number, so make sure you include them or the script won't validate properly.
\r and \n also work, by the way, but these don't need SPACEs after them.
(I love opportunities to promote my plugin)
> replace("\x02 ","\x01 ")
> Important: The SPACE is the marker for the end of the hex number,
> so make sure you include them or the script won't validate properly.
Why SPACE? The symbol '"' must be the end of the hex number - the same as the end of the string - not SPACE!
The symbol '"' is not a valid symbol for a hex-number, so why do we need SPACE? Please change this behaviour.
I did it that way because the hex number is not necessarily the only thing in the replace string.
For example:
replace ("c\xE1 t","cat")
would change all instances of cát to cat.
I could have gone with no terminating character and always assumed a 2-byte hex number, but you can also use decimal numbers by substituting "#" for "x", so in that case you can't make any assumption about the length (except that it's between 1 and 3 digits). To keep it consistent and therefore less confusing, I decided to do it this way for both decimal and hex.
Note that if the first digit in the hex number is 0, you can optionally leave it off. Also note that it only counts the first SPACE after the hex number as the terminating character. A second one would count as an actual SPACE.
You could argue that a SPACE is not the best character to terminate it, and I'm willing to change it if you can convince me that a different character would be better.
I hope that clarifies things.
But I mean this situation: "\x02 ". The SPACE is absolutely needless here because last '"' is the end of the string unambiguously. I'm sure that all users will write just "\x02" and then do not understand why it does not work (personally I will do it ;)).
Or another example: "\x02\x03\x04" - it does not need any SPACE character, are you agree with me? So, IMO, the SPACE is required just - and only - in those cases when you have a letter after your hex number (e.g. "a\x02 b\x03 c\x04\x05").
Yeah, right! The same complaint... I guess the same answers could come up. You can already read it above yours.
I might modify it so that the ending space is not required if a hex or decimal number is the last thing in the string. I can see how that might be easier if you just want to translate a single character.
As for doing it after each hex number if the next one is a hex number too, I suppose it's a reasonable request but the coding on that would be a little tricky, since I would have to check for several different cases (\r, \n, \t, or \q; \\; SPACE; and normal characters) whereas right now I only have to check for a SPACE.
If you'd like to discuss it more, please start a new thread on the SimpleScript forum in the Notepad++ Plugins Project, since we've kind of hijacked this thread.
Thanks.
Good question! What's wrong with hex mode?
Best Regards
Jens