Use Delphi’s own native functions for this, follow example:
vResultado := Trim(Copy(FONTE_TEXTO,1,Pos(' ',FONTE_TEXTO)));
Understand the process:
Trim, vai remover os espaços,
Copy, vai copiar o texto desejado,
FONTE_TEXTO, local onde o texto se encontra,
1, posição de Start da cópia,
Pos, posiciona no final do local ate onde iremos copiar,
' ', é o nosso limitador, ou seja, a posição final da copia,
FONTE_TEXTO, local onde o texto se encontra (nossa fonte do Pos).
Edit:
Following the explanation I gave you just above, just change the position of Start Copy, note that we copy from position 1 to position X based on the separator that is a space, now the position of Star changed as your editing, Let’s just change 1 to a new Search position:
If we know that the text will always be this and formatted this way, instead of informing the 1 we will search with the Pos('<h2>',FONTE_TEXTO)
the initial position!
For the final position we pick up with the Pos(' <STRONG ',FONTE_TEXTO)
To work, we need to delete the rest of the found text, for this we will use a temporary variable, I created a procedure that you can use, it would be something like this:
procedure frmTeste.BtnApurarResultadoClick(Sender: TObject);
var
vTemp : String;
begin
//Procurando o texto, agora com 2 Delimitadores, 1 inicial e 1 final.
vTemp := Trim(Copy(FONTE_TEXTO,Pos('<h2> ',FONTE_TEXTO) + 5,Pos(' <STRONG ',FONTE_TEXTO)));
//Agora deletamos o resto do texto após o número.
Delete(vTemp,Pos(' ',vTemp),Length(vTemp));
//Variavel vResultado alimentada somente com o número apurado!
vResultado := vTemp;
end;
thank you for the reply. The problem is, I’m taking the source code from Webbrowser’s page, and putting it in a memo, the source code is huge, you know? I needed a way to put this function before the word "Hits" as I described in the question. Because it appears as follows: 16600 Hits (I need to take only this number before) remembering that this number can reach the millions also and it changes every moment.
– user7605
So friend, with this procedure I passed, no matter the size of the First character set may be '9384238423423428034234230947345345 Hits' it will capture everything before the Hits!
– Junior Moreira
the problem that BEFORE this access number, has a giant code you understand ? and the ACCESS number in the middle of the page, in case I will have to find the EXACT position of this number to put in Copy, there is an easier way for me to find this position ?
– user7605
Of course there is, but you need to report it, you reported
1678909 Acessos (esse número muda a cada acesso)
so I responded to this case, rsrsrsrs– Junior Moreira
sorry, I corrected the question now. Thank you, if you can help me I thank you.
– user7605
Follow editing in response, we go to tests....
– Junior Moreira
Thank you @Junior Moreira
– user7605
a last question @Junior Moreira, in case the text before the number always changes, I will have to do the opposite, for example capture of the word HITS (which is after the number) and cut before it, is it possible also ? cut after the numbers to get to it ? This example of yours gave right, I will mark as response. If you can help me with just one more question I’d appreciate.
– user7605
Da yes, note that here
Pos('<h2> ',FONTE_TEXTO) + 5
i locate the <H2> and walk 5 forward positions, I can walk 5 backwards or more if you need!– Junior Moreira
Got it @Júnior Moreira, and this SPACE that has between STRONG needs to have even ? in case I would use - 5 then instead of + ?
– user7605
Exact Positive it positions forwards and Negative backwards! The space I just left because it actually exists between it and the number, but does not need!
– Junior Moreira
Okay @Junior Moreira, I will try to do now, any questions I warn you, and thank you so much for your patience.
– user7605
A stupid question @Junior Moreira, why you put + 5 in the case if the number has 7 positions ?
– user7605
It’s not a stupid question, notice that
Pos('<h2> ',FONTE_TEXTO) + 5
it positions at the beginning of '<H2> ' counting the characters is = to 5, ie, besides finding the position I already leave the cursor after this text! rsrsrs Hop of the Cat!– Junior Moreira
Got it @Junior Moreira, rsrsrs, thanks again, I’m testing it here!
– user7605