Forum > Linux

Linux programme - Pos worked, then later it did not

(1/3) > >>

stephanos:
Dear All

I have a funny situation that has developed with Pos.  In a graphical programme I want to use it multiple times to find #10.  I am using a string that has received multiple lines of text from memo.text

--- 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";}};} ---MemoString := Memo1.Lines.Text;The actual content is:

--- Quote ---   Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3
    Didgeridoo Dreaming - Aboriginal Spiritual Music 1/The First Kangaroo.mp3
   Donald Fagen/The Nightfly/Track 02.mp3
   Agua de Pena\ROMARIAS\BAILE DA NOITE.mp3
--- End quote ---
Using Pos and searching on the #10 that must be present at the end of each line I can find and extract the first line of text
Tag := Pos(#10, MemoString); // Tag is 0 at start.  Pos returns zero if not found
path2MP3 := Copy(MemoString, 1, (Tag-1));

I concat an existing string with path2MP3

--- 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";}};} ---path2Musicfolder := concat(path2Musicfolder, path2MP3);I have checked the output using a label caption and the content is correct

--- 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";}};} ---Label3.Caption := path2Musicfolder;Output of:
“/media/stephanos/Sport Go/Music/Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3”

I became suspicious that I was not able to use a third party tool called BASS to retrieve the play time of this MP3 file.  So I did some checking.  I added a ‘[’ to the beginning of the file and a ‘]’ to the end and output to a label caption again.  The output was over 2 lines
Line 1:  [/media/stephanos/Sport Go/Music/Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3
Line 2: ]
Simple I thought, I still have a #10 at the end, and I can remove it, just as I did with MemoString.

First find the position of #10 in the string.  I tried 2 methods and got a return of zero for both.

--- 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";}};} ---Label3.Caption := IntToStr(Pos(#10, path2Musicfolder));and

--- 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";}};} ---Tag := Pos(#10, path2Musicfolder);Label3.Caption := IntToStr(Tag);
This is very peculiar.  Pos could not find the #10 that has to be present.  It must be present because I had output over 2 lines.

Any help appreciated

stephanos:
Sorry too many errors in above I will repost

stephanos:
Dear All

I have a funny situation that has developed with Pos.  In a graphical programme I want to use it multiple times to find #10.  I am using a string that has received multiple lines of text from memo.text

--- 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";}};} ---MemoString := Memo1.Lines.Text;The actual content is:

--- Quote ---   Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3
    Didgeridoo Dreaming - Aboriginal Spiritual Music 1/The First Kangaroo.mp3
   Donald Fagen/The Nightfly/Track 02.mp3
   Agua de Pena\ROMARIAS\BAILE DA NOITE.mp3
--- End quote ---
Using Pos and searching on the #10 that must be present at the end of each line I can find and extract the first line of text

--- Quote ---Tag := Pos(#10, MemoString); // Tag is 0 at start.  Pos returns zero if not found
path2MP3 := Copy(MemoString, 1, (Tag-1));
--- End quote ---

I concat an existing string with path2MP3

--- 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";}};} ---path2Musicfolder := concat(path2Musicfolder, path2MP3);I have checked the output using a label caption and the content is correct

--- 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";}};} ---Label3.Caption := path2Musicfolder;Output of:

--- Quote ---   /media/stephanos/Sport Go/Music/Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3
--- End quote ---

I became suspicious that I was not able to use a third party tool called BASS to retrieve the play time of this MP3 file.  So I did some checking.  I added a ‘[’ to the beginning of the string and a ‘]’ to the end,and output to a label caption again.  The output was over 2 lines
Line 1:  [/media/stephanos/Sport Go/Music/Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3
Line 2: ]
Simple I thought, I still have a #10 at the end, and I can remove it using Pos.

First find the position of #10 in the string.  I tried 2 methods and got a return of zero for both.

--- 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";}};} ---Label3.Caption := IntToStr(Pos(#10, path2Musicfolder));and

--- 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";}};} ---Tag := Pos(#10, path2Musicfolder);Label3.Caption := IntToStr(Tag);
This is very peculiar.  Pos could not find the #10 that has to be present.  It must be present because I had output over 2 lines.

Any help appreciated

cdbc:
Hi
Just for fun -- Try looking for #13  ...maybe they be playing tricks on you  ;D
Another approach would be:
--- 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";}};} ---function PickFirstLineOf(const aStr: string): string;begin  if aStr = '' then exit('');  with TStringlist.Create do try    Text:= aStr;    Result:= Strings[0];  finally Free; end;end; ...Just saying, 'Let the tools given to you, work for you  8)
Regards Benny

Bart:
Why using Pos() to find the next line?
You already have Memo1.Lines.
Just iterate over them:

--- 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";}};} ---  for i := 0 to Memo1.Lines.Count-1 do    DoSomethingWith(Memo1.Lines[i]); 
Bart

Navigation

[0] Message Index

[#] Next page

Go to full version