Hard to explain but need help
-
Hello everyone, I’m in the mist of trying to do a personal project and I’m trying to figure out a way to convert the information in one text file to meet the standards of another. For example let’s say I’m trying to convert these line of text,
Cheat0=“Arms Connect”,80047F77 0022,81047F88 1836,81047F96 E836
Cheat0_N =
Cheat0_O=To this format
cheat0_desc = “Arms Connect”
cheat0_enable = true
cheat0_code = “80047F77 0022;81047F88 1836;81047F96 E836”what would be the best step to achieve this, I’d also like it so if cheat0 text already exists then change it to cheat1 etc
Any help would be great very new to notepad ++
Thank you for the time,
Anthony -
@Anthony-Lovelady
it would seem that a regular expression could fit your needs. However we often have issues with examples loaded like you have. The window you type in uses an interpreter to show the final posting, thus it may be possible for your text to be ‘altered’ slightly.Could you read the FAQ on this forum, specifically
“Request for Help without sufficient information to help you”
as that will make it so much easier to provide you with the right solution.In your example you should supply both the example above and one where you want the cheat0 text existing model.
So before and after examples would be very helpful. As much as you can provide. Some have even provided the entire file, which can be provided by external links.
Pastebin.com is one method to provide examples, there are others.Thanks
Terry -
I think you should take the time to learn a little Java or C (or even Fortran) programming. The answer will then be pretty obvious, and you will have learned a new skill that you will undoubtedly use in other places.
David
-
@Anthony-Lovelady said:
what would be the best step to achieve this, I’d also like it so if cheat0 text already exists then change it to cheat1 etc
When I first answered you this statement was a bit confusing. I suppose my statement in return might have also been a bit confusing.
I’ve since re-interpreted this statement and now consider you are asking whether you can have successive cheat groups created with unique (ascending) numbers. So in the meantime I’ve gone ahead with my interpretations and a possible solution which will:
- Remove unwanted lines. It seems as though the Cheat0_N and Cheat0_O lines aren’t used in any way.
- Preload at the start of each line an increasing number sequence as you require each cheat code to have a unique number.
- With the line that currently exists (after steps above) we divide it up, rearrange and change some text so it fits the final need.
Please read entire post before commencing the steps so you understand what will be occurring.
So load the file into a tab within Notepad++. Some text below is in
red characters
. These can be copied directly from the post and used as stated.So step 1:
Open the Replace function (Ctrl and H keys, read IMPORTANT below).
Find What:(?-s)(Cheat0_N|Cheat0_O).+(\R|\z)
Replace With:<empty field> <—nothing in this field
Click on the “Replace All” button. This removes all the Cheat0_N and Cheat0_O lines.Step 2:
Go to the first line, and click at the start of the line. A cursor symbol (vertical line) should flash before any character on line #1. We will use the Column Editor (Alt and C) to add a sequence of numbers to the start of all lines. Use the “number to insert” option, “initial number” 0 (as per your example) and “increase by” number is 1. Make sure “Dec” is selected and click “OK” button. Every line will start with a number, each 1 higher than the line before.Step 3 (read IMPORTANT below):
Find What:(?-s)(\d+)Cheat\d+(.+?”),(.+)(\R)
Replace With:cheat\1_desc = \2\4cheat\1_enable = true\4cheat\1_code = \3\4
This regex splits the line into the component parts we need to recreate the new version of the line. To give some background:
(?-s) means the “.” character (used in the remainder of the regex) can mean every character EXCEPT a carriage return/line feed. This prevents working on more than 1 line at a time.
(\d+) - means select the digits at the start of line (+ means as many as possible together) and save this as group 1. We will use group 1 later in the “Replace With” field (\1).
Cheat\d+ - we need to pass over this text as I note that your replacement is actually “cheat” (all lower case) with a new number attached. So it is NOT captured as a group.
(.+?”), - this captures the next sequence of characters, the ? means as few as possible until we reach the first occurrence of the “”,” string. This is group 2.
(.+)(\R) - similar to above, except it can only capture to the end of the line and save as group 3. We also capture the carriage return/line feed as group 4.
In the replace field we insert new text along with the groups we already captured, \1 through \4 to create new lines.IMPORTANT: The steps 1 & 3 above require the Replace function to be in “regular expression” mode (see search mode bottom in the “Replace” window) and also have “wrap around” ticked.
I hope this helps. If not, come back to the forum with any issues and additional information that will help.
Terry
-
After posting I was proofing it a second time when I realised that I’d missed the quotes around the data in the cheat0_code line.
So the revised line above should be:
Replace With:cheat\1_desc = \2\4cheat\1_enable = true\4cheat\1_code = “\3”\4
Note quotes around the “\3” near end of that regex. They seem to be the special quotes, not the lowly ones I have on my keyboard ;-D
Terry
-
Thank you for this information and I appologize for not researching further before hand, I will try this when I’m home from work thank you again.
-
Hello, @anthony-lovelady, @terry-r, @david-bailey, and All
As Terry, I was confused about the final goal of the OP. Luckily, Terry almost clarified the problem :-)
I say, “almost”, because we must take in account some other points :
-
We may consider that the initial text contains blocks, separated by blank lines. These blank lines must be deleted, before calling the Column editor !. Otherwise, the numbering wouldn’t be made of consecutive numbers :-((
-
May be, the lines
Cheat0_N =
andCheat0_O=
may contain numbers different from0
, like, for instance,Cheat28_N =
orCheat72_O=
-
Also, the word
Cheat
, in the original text, may be written in lower-case or with any case -
Finally, Terry, I think that you forgot an equal sign
=
, after the partCheat\d+
, in the second regex, at STEP 3
So, given an initial text, as below :
Cheat0=“Arms Connect”,80047F77 0022,81047F88 1836,81047F96 E836 Cheat28_N = Cheat72_O= cheat3=“First_Test”,702A65B7 0198,658CC6D0 9215,8921BF80 C123 cheat3_N = cheat3_O= Cheat12=“Example”,C9245F81 990A,42C845D1 0000,95AD692F A23B Cheat0_N = Cheat2_O= cheat07=“end of the Test”,004F2227 C52D,623C78B2 52F3,692A7D6C 5520 cheat00_N = cheat100_O=
Then, this first regex S/R :
SEARCH
(?i-s)Cheat\d+_(N|O).+\R?|(^\h+\R)+
REPLACE
Leave EMPTY
Would give the text, below :
Cheat0=“Arms Connect”,80047F77 0022,81047F88 1836,81047F96 E836 cheat3=“First_Test”,702A65B7 0198,658CC6D0 9215,8921BF80 C123 Cheat12=“Example”,C9245F81 990A,42C845D1 0000,95AD692F A23B cheat07=“end of the Test”,004F2227 C52D,623C78B2 52F3,692A7D6C 5520
Now, after performing the Column editor action, with a decimal starting number
0
, we obtain :0Cheat0=“Arms Connect”,80047F77 0022,81047F88 1836,81047F96 E836 1cheat3=“First_Test”,702A65B7 0198,658CC6D0 9215,8921BF80 C123 2Cheat12=“Example”,C9245F81 990A,42C845D1 0000,95AD692F A23B 3cheat07=“end of the Test”,004F2227 C52D,623C78B2 52F3,692A7D6C 5520
Finally, using the second regex S/R, below :
SEARCH
(?i-s)(\d+)Cheat\d+=(.+?”),(.+)(\R)
REPLACE
cheat\1_desc = \2\4cheat\1_enable = true\4cheat\1_code = “\3”\4
You should get the expected text :
cheat0_desc = “Arms Connect” cheat0_enable = true cheat0_code = “80047F77 0022,81047F88 1836,81047F96 E836” cheat1_desc = “First_Test” cheat1_enable = true cheat1_code = “702A65B7 0198,658CC6D0 9215,8921BF80 C123” cheat2_desc = “Example” cheat2_enable = true cheat2_code = “C9245F81 990A,42C845D1 0000,95AD692F A23B” cheat3_desc = “end of the Test” cheat3_enable = true cheat3_code = “004F2227 C52D,623C78B2 52F3,692A7D6C 5520”
Best regards,
guy038
-