![]() ![]() It could allow us to better feed human beings and animals, replace plastic and fertilizers, boost medical innovations, mitigate global warming, repair biodiversity and support economies in coastal communities where fish stocks are declining.Īlthough seaweed has supported our development for millions of years, we have lost our connection with it and focused our efforts purely on land cultivation. Incredibly diverse, seaweed could help to bring back balance in our ecosystems through a wide range of applications. ![]() Yet we only know how to cultivate a few dozen varieties, at most. Seaweed develops in water everywhere, from the eternal glaciers to lagoons heated by the sun, from seas saturated with salt to the fresh water of our rivers. (HT Team) 279pp, ₹799 Hero Press (Fresh hope for tomorrow) Writeln('WordPos: ', WordList.WordPos, ' WordStr: ', WordList.Reconsidering a forgotten marine treasure This week’s interesting reads includes a volume on how seaweed could allow us to better feed human beings and mitigate global warming, a cook book that celebrates quick, healthy foods prepared with minimal fuss, and the autobiography of the man who revolutionised the electoral process in India. MyPhrase := 'A crossword contains words but not WORD' This gives the result as required in the question:ĮDIT: I have now simplified the code by using WordRec.WordPos := MatchResult.Index ĮDIT2: Cleaned up the uses list program MyTokenize List.AddObject(Fragment, TObject(Parser.SourcePos)) Where the token fragments occur, as follows In case it isn't obvious, it's trivial to obtain the positions in the source string A partial wor' įragment := Copy(Parser.TokenString, 1, Length(Target)) ![]() MyPhrase := 'I have a simple word and a complex Word: A lot of WORDS. It shows, btw, that the use of constructs such a PWordRec and manual allocation and de-allocation of the 'tokens' are not necessary. In 'WORDS' precludes a direct comparison between the Target stringĪnd Parser.TokenString and necessitates the derivation of Fragment as written. Of course, the OP's requirement that the code should match the 'WORD' Tokenizes the input in the same way Delphi's compiler does. Largely for my own amusement, I decided to write an answer which Had I not chosen to use a function, but placed all code in one block, I could have iterated over the TList in exactly the same way: for var Match in List do Now, let's use this function: procedure TWordFinderForm.ePhraseChange(Sender: TObject) įor var Match in GetPhraseMatches(mText.Text, ePhrase.Text) do Also notice how easy it is to work with the TList: it's just like a TStringList but with word records instead of strings! Notice that I chose an alternative to the regular expression approach, just for educational reasons. Match.Text := Copy(AText, p, APhrase.Length) Instead, I populate a local TList and then, as a last step, create an array from it: typeįunction GetPhraseMatches(const AText, APhrase: string): TArray By definition, this is simply array of TWordRec, that is, a dynamic array of TWordRecs.īut how to efficiently populate such an array? We all know you shouldn't increase the length of a dynamic array one element at a time besides, that requires a lot of code. I could have this function return or populate a TList, but then it would be tiresome to work with it, because the user of the function would then need to add try.finally blocks every time the function is used. On request, here is how I would do this myself:įirst, I want to create a function that performs this operation, so it can be reused every time we need to do this. When the project's Build Configuration is set to Release then there is no AV. ![]() Unfortunately, it has a strange bug: It gets an AV exactly at the THIRD for loop!ĮDIT2: It seems that the AV happens only when the project's Build Configuration is set to Debug. WriteLn(' Press Enter to free the list') Writeln('WordPos: ', WordList.WordPos, ' WordStr: ', WordList.WordStr) MyPhrase := 'A crossword contains words but not WORD' Result := PWordRec(inherited Get(Index)) Property Items: PWordRec read Get default įunction TWordList.Add(Value: PWordRec): Integer įunction TWordList.Get(Index: Integer): PWordRec Of course, writing such a function is trivial, but I wonder if there already is a procedure for this in the existing huge Delphi code treasure.ĮDIT: I am experimenting with a wordlist that should have the required features: program MyTokenize Searching for "tokenize string" in the Delphi documentation did not get any useful results for this purpose. (IntToStr(MyTokens.Pos) + ': ' + MyTokens.String) MyTokens := MyTokenize(MyPhrase, 'word') Does Delphi (10.4) have a string-tokenizer that extracts string-token-objects from a string in a similar way as below? MyPhrase := 'I have a simple word and a complex Word: A lot of WORDS.' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |