Hello again.
Well i substitute the
c string read from text for a "inserted" on code and it works (example c:=' 1 2 3 '), with or without the function "tidymystring"... strange... so...
I start to check some thinks, i concluded that the problem is in the txt... if it is recorded in ANSI it works fine (cut the spaces at begenning and repeated, and split the numbers)), if it is recorded as UTF-8 it does not work as expected to trim the initial space.
And why i was recording the txt file in UTF-8? Well because i was testing in other file reading text with accents (Portuguese language- "Cão último país"). If recorded in ANSI dont read the accents.
Thanks for all. As i said at begenning, i´m just trying to program in Lazarus, as alternative to VB net, just need some simple programs with light interface, mainly to read data and to make something wit that data and then record the results...at maximum draw some simple graphics... the VB Net comunity put in disk at least 3 GB, it absurd.
I program manily in Lua now, its very very fast, but dont have a GUI by default and dont make exe. For me is fine, but to send to other in my company, its bad.
Thanks again.
Hi
Maybe something like
const my_delim=' ';
var s:string;
s:=' 1 2 3 4 5 6 7 8 9';
//remove the beginning spaces
s:=TrimLeft(s);
showmessage('|'+s+'|');
// replace any double spaces with single spaces
while pos(my_delim+my_delim,s)>0 do s:=stringreplace(s, my_delim+my_delim,my_delim,[rfReplaceAll, rfIgnoreCase]);
showmessage('|'+s+'|');
edit:
or as a function
function tidymystring(s:string;my_delim:char):string;
begin
s:=trimleft(s);
if my_delim<>chr(0) then // if delimeter is #0 then only do a trimleft
begin
while pos(my_delim+my_delim,s)>0 do s:=stringreplace(s, my_delim+my_delim, my_delim,[rfReplaceAll, rfIgnoreCase]);
end;
result:=s;
end;
use like
showmessage(tidymystring(' 1 2 3 4 5 6',' ')); // second param is a space
result
1 2 3 4 5 6
showmessage(tidymystring(' 1 2 3 4 5 6',chr(0))); // second param chr(0) which allows just a trimleft
result
1 2 3 4 5 6
or in your code
readln(ficheiro3, c);
c:=tidymystring(c,' '); // second param is a space
Lista1.Delimiter := ' ';
Lista1.DelimitedText := c;
x:=Lista1.Count;