Recent

Author Topic: SplitString issue  (Read 1040 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 605
SplitString issue
« on: February 11, 2025, 06:19:15 pm »
I am using Lazarus 3.2 in a simple FPC program on Linux.  Very briefly, I have code something like this:

Code: Pascal  [Select][+][-]
  1. var
  2.   Message: TStringArray;
  3.   S: string;
  4.   ...
  5.  
  6. begin
  7.   S := 'A,B,C';
  8.   Message := SpitString(S,',');
  9.   ...
  10.  
  11. end;
  12.  

I've discovered that rather than the TStringArray Message containing  the items A,B and C it contains 'A'#$0A, 'B'#$0A,'C'#0A
according to my Watches -- that is, each element has an appended line feed.   Is there a way to eliminate the line feeds?  I have a similar use of TString Array and StringSplit in a Lazarus GUI application and the line feeds don't seem to appear there.  Or are the single quote characters and the line feed an artifact of the Watch window?

Thanks.
 

« Last Edit: February 11, 2025, 06:57:43 pm by Curt Carpenter »

cdbc

  • Hero Member
  • *****
  • Posts: 1930
    • http://www.cdbc.dk
Re: SplitString issue
« Reply #1 on: February 11, 2025, 06:30:05 pm »
Hi
Curt, you can do better than that...
Code: Pascal  [Select][+][-]
  1. A,B,C;
...are they constants, variables or something from scrabble?!?
Code: Pascal  [Select][+][-]
  1. S:= 'A,B,C'; { if you want a string }
  2. S:= A + ',' + B + ',' + C; { if they're consts or vars}
Write us a piece of code that makes sense, NONE of us can read minds  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 605
Re: SplitString issue
« Reply #2 on: February 11, 2025, 06:59:48 pm »
Hi
Curt, you can do better than that...

Yes, sorry:  added the single quotes in the OP.  Been working on this problem all morning and think I'm going blind.  Probably need a break.  Other problems in the OP too -- will come back later after a walk.
« Last Edit: February 11, 2025, 08:02:03 pm by Curt Carpenter »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: SplitString issue
« Reply #3 on: February 11, 2025, 08:41:43 pm »
I've discovered that rather than the TStringArray Message containing  the items A,B and C it contains 'A'#$0A, 'B'#$0A,'C'#0A
according to my Watches -- that is, each element has an appended line feed.

I just tried that on Windows Win10 64 bit => no linefeeds

Lazarus 4.99 (in case the older IDE messed up watches / not that I recall any such bug)
FPC 3.2.2 and 3.2.3 (both tested)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 605
Re: SplitString issue
« Reply #4 on: February 11, 2025, 09:09:31 pm »
Yes, it was me.  The string wasn't 'A,B,C' but 'A,B,C#10"  as received -- so my OP messed up in multiple regards. 

VisualLab

  • Hero Member
  • *****
  • Posts: 639
Re: SplitString issue
« Reply #5 on: February 11, 2025, 09:11:17 pm »
I also checked the given example (Lazarus 3.4, Windows 10 64-bit). Degugger works correctly, as expected, even though I use an older IDE :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: SplitString issue
« Reply #6 on: February 11, 2025, 09:40:51 pm »
2 things though about the debugger.

1) Which one did you @Curt Carpenter use? Gdb or FpDebug
2) Which setting for debug info? Dwarf 2 or 3?

There may be an odd version of gdb doing something odd....

But also, if you use Dwarf 2 (that is Dwarf, or dwarf-with-sets / anything NOT labelled "dwarf 3"), then FPC does write strings in a form that is not distinguishable from Pchar. 
Though even then
- there would be 'a'#0  Strings always have a leading #0 byte
- FpDebug would display 2 results labelled string and pchar.

But of course, I don't know what the odd version of GDB would do.


--------EDIT
Just saw you found something else...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8306
Re: SplitString issue
« Reply #7 on: February 11, 2025, 10:26:17 pm »
- there would be 'a'#0  Strings always have a leading #0 byte

Leading?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10897
  • Debugger - SynEdit - and more
    • wiki
Re: SplitString issue
« Reply #8 on: February 11, 2025, 10:43:53 pm »
- there would be 'a'#0  Strings always have a leading #0 byte

Leading?

RTL (right to left) ordering... ;)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8306
Re: SplitString issue
« Reply #9 on: February 11, 2025, 10:47:11 pm »
RTL (right to left) ordering... ;)

Ah. Just like APL: parses LTR then evaluates RTL.

Let's not go there, Curt's smart enough to work it out :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 16623
  • Kallstadt seems a good place to evict Trump to.
Re: SplitString issue
« Reply #10 on: February 12, 2025, 11:20:17 am »
Besides, a stringarray is not a chararray and strings always have a termination zero even if they are just one character long.
But I am sure they don't want the Trumps back...

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 605
Re: SplitString issue
« Reply #11 on: February 12, 2025, 05:31:44 pm »
No no -- the whole problem was down to me not being careful and making assumptions about what was going on.  Everything is working fine.  Should have taken that walk before I posted here -- sorry.

 

TinyPortal © 2005-2018