Recent

Author Topic: [SOLVED] pos(LineEnding) = 0 in Windows ?  (Read 5572 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
[SOLVED] pos(LineEnding) = 0 in Windows ?
« on: November 23, 2014, 12:46:48 pm »
Hello everybody.

I have some trouble with LineEnding in Windows...

Take a look a that =>
Code: [Select]
...
var
TheData : string;
ThePos : integer;
...

TheData :=

´ this
    this
this
,
;

ThePos := pos( 'this' + LineEnding, TheData);
writeln('the position is: ' +  inttostr(ThePos);
...         

With Linux, perfect ThePos > 0 but with Windows ThePos = 0 ;

I have try with
ThePos := pos( 'this' + #10, TheData);
and with ThePos := pos( 'this' + #13, TheData);

But in Windows => always ThePos = 0  :-X

How to do that in Windows ?

Thanks.

Fre;D

« Last Edit: November 23, 2014, 08:36:45 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: pos(LineEnding) = 0 in Windows ?
« Reply #1 on: November 23, 2014, 02:44:10 pm »
I guess you did not define TheData in code like above?
Where do you get TheData from (a TMemo perhaps)?

Bart

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: pos(LineEnding) = 0 in Windows ?
« Reply #2 on: November 23, 2014, 02:44:38 pm »
Indeed.
Never knew this syntax was allowed!?
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: pos(LineEnding) = 0 in Windows ?
« Reply #3 on: November 23, 2014, 02:51:32 pm »
Note that if you put:

Code: [Select]
Data = 'abcd efgh ' +
           'ijkl mnop';

There is no LineEnding in the Data string

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: pos(LineEnding) = 0 in Windows ?
« Reply #4 on: November 23, 2014, 02:56:17 pm »
win uses [\r\n]
nix uses [\n]
is a common issue when transferred files from nix to win and vise versa

Edit***:Try this to ensure is working
the search is case sensitive and you might been tricked from the space after the [this] and the line ending

Code: [Select]
var
TheData : string;
ThePos : integer;
begin
   TheData :=' this1' + LineEnding;
   TheData:=TheData+' this' + LineEnding;
      TheData:=TheData+' this ' + LineEnding;


ThePos := pos( 'this' + LineEnding, TheData);
writeln('the position is: ' +  IntToStr(ThePos)); 
« Last Edit: November 23, 2014, 03:07:16 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: pos(LineEnding) = 0 in Windows ?
« Reply #5 on: November 23, 2014, 07:39:13 pm »
Hello everybody and many thanks to help.  ;)

I must explain a little more.

TheData was filled from a text file.

That text file contain somes LineEnding inside.

When i do x := pos( 'this' + LineEnding, TheData); in linux a get  x > 0 ;

But in Windows, with the same file i get x = 0  :'(

It seams that Windows do not find LineEnding nor #10 nor #13.

So how could i do to localizse a word followed by a LineEnding in Windows.

Thanks.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: pos(LineEnding) = 0 in Windows ?
« Reply #6 on: November 23, 2014, 07:42:20 pm »
@Fred vS
please provide example of text of yours
the source i posted is working fine in win
Edit***: in win line ending is [ #13#10 ]
« Last Edit: November 23, 2014, 07:45:06 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: pos(LineEnding) = 0 in Windows ?
« Reply #7 on: November 23, 2014, 07:47:44 pm »
Maybe there are no line-endings. Reason: plain text file is a very simple format. If that text-file was created in Linux, then line-endings are #10 and Windows cannot read it correctly.
Furthermore, sometimes text files have no line-ending at all and line-wrapping is done only by settings of the text-editor.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: pos(LineEnding) = 0 in Windows ?
« Reply #8 on: November 23, 2014, 08:00:09 pm »
Quote
the source i posted is working fine in win
Indeed, here in Wine it is working too, so it is a problem of decoding the text file.
When trying your source with TheData filled with a simple text file with some line-ending it is not working in Windows.

Quote
Maybe there are no line-endings. Reason: plain text file is a very simple format. If that text-file was created in Linux, then line-endings are #10 and Windows cannot read it correctly.
Hum, not sure because that file was done with gedit, but maybe...

Quote
Edit***: in win line ending is [ #13#10 ]
Yes i have try but it does not work  :-[


I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: pos(LineEnding) = 0 in Windows ?
« Reply #9 on: November 23, 2014, 08:07:54 pm »
Try
Code: [Select]
  TheData :=   AdjustLineBreaks(TheData);

before searching for LineEndings.

Bart

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: pos(LineEnding) = 0 in Windows ?
« Reply #10 on: November 23, 2014, 08:16:40 pm »
Quote
Try
Code: [Select]

  TheData :=   AdjustLineBreaks(TheData);


before searching for LineEndings.

Bart

Ooops, that is a beautiful one, i will try it ASAP  ::)
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: pos(LineEnding) = 0 in Windows ?
« Reply #11 on: November 23, 2014, 08:35:43 pm »
@ Bart => You are MY Hero tonight => It works  ;D

Code: [Select]
TheData :=   AdjustLineBreaks(TheData); => Does the trick.

Many, many thanks.

Fre;D


I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018