Forum > General
Make StringList from Unicode string with '\n'
Sniper:
I have unicode string from THtmlviewer.DocumentSource.
Now I need to go through this string.
some pseudocode:
--- 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";}};} ---varHTMLString: WideString;i:integerfList:TStringList;fList := TStringList.Create(); while (true) do begin fList.Add(); if (HTMLString[i] <> '\n') break; inc(i); end;
marcov:
--- Code: ---if (HTMLString[i] <> '\n')
--- End code ---
Htmlstring\[i\] is one char. '\n' is two, so they are never equal ?
Maybe you try something else than a backslash and an n?
taazz:
stringlist already breaks on line ends just do
--- 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";}};} ---varHTMLString: WideString;i:integerfList:TStringList;begin fList := TStringList.Create(); fList.Text := HTMLString;end; that should give you multiple lines. as far as I know there is no escape character support in string in pascal you have to define your character by code I suggest to use #10 it will always break correctly the lines regardless of line end format.
Sniper:
--- Quote from: marcov on April 25, 2018, 04:16:28 pm ---
--- Code: ---if (HTMLString[i] <> '\n')
--- End code ---
Htmlstring\[i\] is one char. '\n' is two, so they are never equal ?
Maybe you try something else than a backslash and an n?
--- End quote ---
End of line always \r\n or #10#13. I don't know what it should be here.
Sniper:
--- Quote from: taazz on April 25, 2018, 04:28:14 pm ---stringlist already breaks on line ends just do
--- 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";}};} ---varHTMLString: WideString;i:integerfList:TStringList;begin fList := TStringList.Create(); fList.Text := HTMLString;end; that should give you multiple lines. as far as I know there is no escape character support in string in pascal you have to define your character by code I suggest to use #10 it will always break correctly the lines regardless of line end format.
--- End quote ---
Nice. What a simple solution! I'll try it.
Navigation
[0] Message Index
[#] Next page