Linux programme - Pos worked, then later it did not lazarus / 32-Linux ---------------------------------------------------------------------- stephanos · 2025-09-17 18:26 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.mp3Using 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i path2Musicfolder := concat(path2Musicfolder, path2MP3);I have checked the output using a label caption and the content is correct Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Label3.Caption := IntToStr(Pos(#10, path2Musicfolder));and Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2025-09-17 18:28 Sorry too many errors in above I will repost ---------------------------------------------------------------------- stephanos · 2025-09-17 18:34 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.mp3Using 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 QuoteTag := 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i path2Musicfolder := concat(path2Musicfolder, path2MP3);I have checked the output using a label caption and the content is correct Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Label3.Caption := path2Musicfolder;Output of: Quote   /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 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Label3.Caption := IntToStr(Pos(#10, path2Musicfolder));and Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2025-09-17 18:42 Hi Just for fun -- Try looking for #13  ...maybe they be playing tricks on you  Another approach would be:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  Regards Benny ---------------------------------------------------------------------- Bart · 2025-09-17 20:55 Why using Pos() to find the next line? You already have Memo1.Lines. Just iterate over them: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   for i := 0 to Memo1.Lines.Count-1 do    DoSomethingWith(Memo1.Lines[i]);  Bart ---------------------------------------------------------------------- jamie · 2025-09-17 21:37 He's been told countless times to not use the "TEXT" like this. ---------------------------------------------------------------------- Thausand · 2025-09-18 11:37 When know then easy, when not know difficult  @stephanos See no-print character difficult. Then choice not use print character for see. Same is when copy-paste text. You write this is text you have in program (have copy in post) but is no true. Then other person not can help find error. You also have describe what happen but situation not reproduce for other. Then not find answer when ask help. TMemo have property Lines (default property) type TStrings and is act same TStringList (is ancestor type TStrings), they same. When use property TMemo Text then stuff happen that not know (I not want know because no relevant). I want know characters for Line and no Text. When TMemo.Lines then all line is individual store/access and (when all good) have no non-print character. Character stop when Line break and break line not store in Line. Then no require search non-print character and make solution more easy. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...var  index:integer;  songers:TStringList;  Path2musicfolder:string;  Song:string; Path2musicfolder:='/media/stephanos/Sport Go/Music';songer:=TStringList.Create; for index:=0 to Memo1.Lines.Count-1 dobegin  // 1st: Path2Mp3:=Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3  Path2Mp3:=Memo1.Lines[index];    // song  := '/media/stephanos/Sport Go/Music/Alasdair Roberts/Farewell Sorrow/Farewell Sorrow.mp3'  song:= ConcatPaths(Path2musicfolder, Path2Mp3);    // if want make clean begin/end. Is alert when name have space or valid non-print begin/end  song:=trim(song);   // add for songer, now have copy memo line  songer.Add(song);end; // now have use songerfor song in songer do var  p:string;begin  // have indicate #13 #10 when write  if song.contains(#13) or song.contains(#10) then p:='XXX ' else p := '';   // write terminal if can  writeln(p + ' ' + song);    // write memo for show  Memo1.Lines.Append(p + ' ' + song);end; songer.Free;...  Can have other problem when unicode and problem path separator but is simple example for show how can make work. I not have all understand what explain do. Please have share work code when need help more. I have make copy songer for lines TMemo but can have omit then use memo direct. I no understand explain and what is result want. ---------------------------------------------------------------------- stephanos · 2025-09-18 18:59 Dear cdbc and all Spot on.  #13, not #10 – Solved Thanks Case closed, but another coming soon ---------------------------------------------------------------------- Fred vS · 2025-09-18 23:48 Quote from: stephanos on September 18, 2025, 08:59:58 pmSpot on.  #13, not #10 – Solved Instead of #13 you may use lineending constant, it is cross-platform. ---------------------------------------------------------------------- ccrause · 2025-09-19 05:46 Quote from: Fred vS on September 19, 2025, 01:48:38 amQuote from: stephanos on September 18, 2025, 08:59:58 pmSpot on.  #13, not #10 – Solved Instead of #13 you may use lineending constant, it is cross-platform. Since the OP is working with a TStrings decendant, rather use the linebreak property for internal consistency. ---------------------------------------------------------------------- CM630 · 2025-09-19 05:52 Quote from: Fred vS on September 19, 2025, 01:48:38 am... Instead of #13 you may use lineending constant, it is cross-platform. For TMemo it might be OS dependent, but I am pretty sure that for TRichMemo it is not. So if one decides to convert later, it might be a problem. @stephanos, I avoid TStringList as much as possible, but it is an essential part of Lazarus (and maybe other languages), and sooner or later you will find out that you are going nowhere without it. I would advise you to learn how to use it. The way you are handling the current situation (as many people already told you) is far from the best.