Forum > Beginners

Split a string in words

(1/3) > >>

funlw65:
I have a string composed of four words of arbitrary length, separated by ";" character.
Example:
"Costica;Ana;Andrei;Ema"

Not a single word will be empty, so checking is not necessary.

I came with two methods, compiling the program with any of it activated, I get the same code size.

Any other method?

tr_escape:
Long time ago I was using this function:

https://github.com/mehmetulukaya/muterm/blob/fa2d83ec5c7c327b1f03d5a3b35b77c69e713058/MuLibs.pas#L213

But maybe there are built-in function about parsing words like as:

https://www.freepascal.org/docs-html/rtl/strutils/splitstring.html

funlw65:
Thank you for the links, I prefer not to use dynamic allocation...

dsiders:

--- Quote from: funlw65 on January 05, 2022, 05:33:20 am ---Thank you for the links, I prefer not to use dynamic allocation...

--- End quote ---

Then use TStringList and set its Delimiter and DelimitedText properties.

Roland57:
Another possibility:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Uses StrUtils; var  i: integer;  Begin  { ... }  for i := 1 to WordCount(pigeon_record, [';']) do  begin    WriteLn(ExtractWord(i, pigeon_record, [';']));  end;End.

Navigation

[0] Message Index

[#] Next page

Go to full version