Pedro Caldeira Active Member Licensed User Longtime User Feb 25, 2022 #1 Hello All, I am trying to read an html string stored in a mediumtext type field in (sqlite) If I copy the string directly, paste it into a file, save it as html as read it, its correct. But if I read it in B4A, reading it from a resultset to a string, its loses its format. I get . (dot) in place of CRLF, etc. I already tried to use textwriter with UTF-8 encoding , getbytes and bytestostring with the html data, nothing. Is there a way to get around this ? Examples of the strings copied From DB field and pasted to notepad++ Code: <div class="row" style="margin-top:50px; margin-bottom: 10px; min-height:0px"> <div class="col-4"> <div style=""> <p style="text-align:left">:__REPORT_MODEL</p> </div> </div> <div class="col-4"> <div style=""> <p style="text-align:center; opacity: 0.5; color:#C9CCD5">:__EXECUTION_NUMBER</p> </div> </div> <div class="col-4"> <div style=""> <p style="margin-right:25px; text-align:right">Página {PAGENO} de {nb}</p> </div> </div> </div> copied from the resultset and pasted to notepad++ Code: <div class="row" style="margin-top:50px; margin-bottom: 10px; min-height:0px">. <div class="col-4">. <div style="">. <p style="text-align:left">:__REPORT_MODEL</p>. </div>. </div>. . <div class="col-4">. <div style="">. <p style="text-align:center; opacity: 0.5; color:#C9CCD5">:__EXECUTION_NUMBER</p>. </div>. </div>. . <div class="col-4">. <div style="">. <p style="margin-right:25px; text-align:right">Página {PAGENO} de {nb}</p>. </div>. </div>. </div>
Hello All, I am trying to read an html string stored in a mediumtext type field in (sqlite) If I copy the string directly, paste it into a file, save it as html as read it, its correct. But if I read it in B4A, reading it from a resultset to a string, its loses its format. I get . (dot) in place of CRLF, etc. I already tried to use textwriter with UTF-8 encoding , getbytes and bytestostring with the html data, nothing. Is there a way to get around this ? Examples of the strings copied From DB field and pasted to notepad++ Code: <div class="row" style="margin-top:50px; margin-bottom: 10px; min-height:0px"> <div class="col-4"> <div style=""> <p style="text-align:left">:__REPORT_MODEL</p> </div> </div> <div class="col-4"> <div style=""> <p style="text-align:center; opacity: 0.5; color:#C9CCD5">:__EXECUTION_NUMBER</p> </div> </div> <div class="col-4"> <div style=""> <p style="margin-right:25px; text-align:right">Página {PAGENO} de {nb}</p> </div> </div> </div> copied from the resultset and pasted to notepad++ Code: <div class="row" style="margin-top:50px; margin-bottom: 10px; min-height:0px">. <div class="col-4">. <div style="">. <p style="text-align:left">:__REPORT_MODEL</p>. </div>. </div>. . <div class="col-4">. <div style="">. <p style="text-align:center; opacity: 0.5; color:#C9CCD5">:__EXECUTION_NUMBER</p>. </div>. </div>. . <div class="col-4">. <div style="">. <p style="margin-right:25px; text-align:right">Página {PAGENO} de {nb}</p>. </div>. </div>. </div>
drgottjr Expert Licensed User Longtime User Feb 25, 2022 #2 i would use: B4X: dim buffer() as byte = rs.GetBlob("field_name") dim defstring as string = BytesToString( buffer, 0, buffer.Length, "UTF8") the encoding is most likely UTF8, but keep iso-8859-1 and windows-1252 in mind. you might have to try with different encoding. the "." is the key to the solution (for me, at least). you also refer to "etc". i don't know what else you're including in that. the "." is chr(10), aka CRLF in b4a, but sqlite appears to convert it for storage as a string (which it isn't). if you know you'll have non-printing characters in your string, you could store it as a blob in the first place. in one of my databases, i have non-printing characters in some strings. i store them as text, but i found that i had to read them back as blob and then convert to string in order not to lose those characters. i'm guessing it's the same story for you. Upvote 0
i would use: B4X: dim buffer() as byte = rs.GetBlob("field_name") dim defstring as string = BytesToString( buffer, 0, buffer.Length, "UTF8") the encoding is most likely UTF8, but keep iso-8859-1 and windows-1252 in mind. you might have to try with different encoding. the "." is the key to the solution (for me, at least). you also refer to "etc". i don't know what else you're including in that. the "." is chr(10), aka CRLF in b4a, but sqlite appears to convert it for storage as a string (which it isn't). if you know you'll have non-printing characters in your string, you could store it as a blob in the first place. in one of my databases, i have non-printing characters in some strings. i store them as text, but i found that i had to read them back as blob and then convert to string in order not to lose those characters. i'm guessing it's the same story for you.