Jump to content
Macro Express Forums

crop a text precisely


Recommended Posts

Hello,

 

I'm not beginner with ME 4.9.1 but I never done this before.

 

I want to treat a page where is 15 times this kind of data :

Quote

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=
400     Il y a 15 Heure
Icône

 

I want to trim this text in order to keep only one of the two numbers I underlined.

Every text in each line can change, except "X" and "=", but I just want to keep one of the two "400" in this exemple. 

 

I need this in order to refresh the entiere text, compare the one before, and the one after, and ring if there is a difference. But I'm able to do this part. 

 

Thank you for help. 

Link to comment
Share on other sites

Hi,

 

Perhaps because I have not yet had my first coffeee, but I’m not clear about the result you want from that example.

 

I assume I this is your INPUT:
 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=
400     Il y a 15 Heure
Icône

 

So is your OUTPUT this?

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=

   Il y a 15 Heure
Icône

 

Or this?

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
X

=
400     Il y a 15 Heure
Icône

 

Or this?

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=
Icône

 

Or this?

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=

Il y a 15 Heure
Icône

 

Or something else?

 

Terry

Link to comment
Share on other sites

1. I think you are saying that you want the macro to examine 15 blocks of text, and that each block is in this 11-line format:

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X

=
400     Il y a 15 Heure
Icône

 

2. Can you express the number you are monitoring as a range? For example, the number you are looking for can have these values:

 

minimum value: 100

maximum value: 999

 

3. Where will these blocks of text be located? In a database? In a plain text file? In a Word document? In a spreadsheet?

Link to comment
Share on other sites

10 minutes ago, terrypin said:

To remove all ambiguity why don't you simply show two examples of the input and output?

 

 

Ceinture de Bloublou
Niveau  160
@DonarX11
Michto : Kipu
Orkou IV
400 
X
1 
=
400     Il y a 15 Heure
Icône

Ceinture de RATRRR
Niveau  160
@Zfeee
eeffff: ttrrr
Ertzzy
525 
X
4
=
2100     Il y a 16 Heure
Icône

 

Become :

400, 525

Or

400, 2100

 

Thank you. 

Link to comment
Share on other sites

I woudl use Text File Process to go though each line. On the 6th and 10th line and each interval there after I'd find the first occurrence of the space and take only the characters up to that. So if the space was at 4, take the substring 1 though 3. 

This is assuming the line counts are consistent. 

Link to comment
Share on other sites

3 minutes ago, Cory said:

I woudl use Text File Process to go though each line. On the 6th and 10th line and each interval there after I'd find the first occurrence of the space and take only the characters up to that. So if the space was at 4, take the substring 1 though 3. 

This is assuming the line counts are consistent. 

 

That's not 😁

Link to comment
Share on other sites

If the organization of lines is not consistent, then this will be a very challenging project!

 

Is there always a line that starts with the word "Niveau?" Can we always ignore the number on that line?

 

Does the time always appear? (E.g., "Il y a 16 heures") Can we always ignore the time?

 

If a number appears on a line by itself, can we always ignore that number?

Link to comment
Share on other sites

Sorry, maybe I have a easier way :

 

1 - Is it possible to keep a text between 2 words ? For exemple :

xoops

hello blablabla

51616

 

Keep only "hello blablabla"

 

2 - Is the new version of macro express able to monitor changes visualy on a web page ? 

Link to comment
Share on other sites

56 minutes ago, ikodan said:

1 - Is it possible to keep a text between 2 words ? For exemple :

xoops

hello blablabla

51616

 

Keep only "hello blablabla"

 

 

Yes... but you must know, or be able to calculate, the position of "hello blablabla" within the string. Does it always appear on a certain line? If yes, which line? Does "xoops" always appear before and "51616" always appear afterwards? Does the "H" in "hello blablabla" always appear as the n-th character in the string?

Link to comment
Share on other sites

No problem capturing the text between  "X" and "=".

 

But for this approach to work, you must make sure that "X" and "=" only appear once in the string. The code might look something like this:

 

Variable Set String %Data% to "Ceinture de Bloublou
Niveau  160
@Donarx11
Michto : Kipu
Orkou IV
999 
X
12345 
=
140     Il y a 15 Heure
Icône"
Variable Modify String: Replace " " in %Data% with "" // I don't think we need the spaces
Variable Set Integer %PositionX% to the position of "X" in %Data%
Variable Modify Integer: %PositionX% = %PositionX% + 2
Variable Set Integer %PositionEquals% to the position of "=" in %Data%
Variable Modify Integer: %PositionEquals% = %PositionEquals% - 1
Variable Modify Integer: %CharactersToCopy% = %PositionEquals% - %PositionX%
Variable Modify String: Copy part of text in %Data% starting at %PositionX% and %CharactersToCopy% characters long to %Data%
Text Box Display: Result

<VARIABLE SET STRING Option="\x00" Destination="%Data%" Value="Ceinture de Bloublou\r\nNiveau  160\r\n@Donarx11\r\nMichto : Kipu\r\nOrkou IV\r\n999 \r\nX\r\n12345 \r\n=\r\n140     Il y a 15 Heure\r\nIcône" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x0F" Destination="%Data%" ToReplace=" " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="I don't think we need the spaces"/>
<VARIABLE SET INTEGER Option="\x0E" Destination="%PositionX%" Text_Variable="%Data%" Text="X" Ignore_Case="FALSE"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%PositionX%" Value1="%PositionX%" Value2="2"/>
<VARIABLE SET INTEGER Option="\x0E" Destination="%PositionEquals%" Text_Variable="%Data%" Text="=" Ignore_Case="FALSE"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%PositionEquals%" Value1="%PositionEquals%" Value2="1"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%CharactersToCopy%" Value1="%PositionEquals%" Value2="%PositionX%"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%Data%" Variable="%Data%" Start="%PositionX%" Count="%CharactersToCopy%" NoEmbeddedVars="FALSE"/>
<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs20 %PositionEquals% - %PositionX% = %CharactersToCopy%\r\n\\par \r\n\\par [%Data%]\\lang1033\\f1\\fs14 \r\n\\par }\r\n" Left="5" Top="417" Width="1719" Height="294" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...