Massy Member Licensed User Longtime User Jun 21, 2014 #1 Hi, I am trying to split a very long line of code into many lines but with no success... I have a string variable that is very large as it has an html code inside... so I'm trying to have it in many lines and not in just one line but I can't find how to do it... This is an example of my code: Dim Html As String Html = "<p align=""center""><font color=""#3D1565"" size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" and I need to split it in two lines... something like this: Html = "<p align=""center""><font color=""#3D1565"" size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" How should I do it? Thanks for any help Massy
Hi, I am trying to split a very long line of code into many lines but with no success... I have a string variable that is very large as it has an html code inside... so I'm trying to have it in many lines and not in just one line but I can't find how to do it... This is an example of my code: Dim Html As String Html = "<p align=""center""><font color=""#3D1565"" size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" and I need to split it in two lines... something like this: Html = "<p align=""center""><font color=""#3D1565"" size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" How should I do it? Thanks for any help Massy
NJDude Expert Licensed User Longtime User Jun 21, 2014 #2 Instead of having that long HTML line, save it as a file and do this: Code: Copy Dim Html As String Html = File.ReadString(File.DirAssets, "myHtml.html") However, if you insist on splitting that line then you can do this: Code: Copy Html = "<p align=""center""><font color=""#3D1565""" & _ "size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" But that's too cumbersome. Also, use single quotes as delimiters for your HTML code, it's easier to handle, for example: Code: Copy Html = "<p align='center'><font color='#3D1565'" & _ "size='3' face='Verdana, Arial, Helvetica, sans-serif'>HELLO WORLD <br />" Last edited: Jun 21, 2014 Upvote 0
Instead of having that long HTML line, save it as a file and do this: Code: Copy Dim Html As String Html = File.ReadString(File.DirAssets, "myHtml.html") However, if you insist on splitting that line then you can do this: Code: Copy Html = "<p align=""center""><font color=""#3D1565""" & _ "size=""3"" face=""Verdana, Arial, Helvetica, sans-serif"">HELLO WORLD <br />" But that's too cumbersome. Also, use single quotes as delimiters for your HTML code, it's easier to handle, for example: Code: Copy Html = "<p align='center'><font color='#3D1565'" & _ "size='3' face='Verdana, Arial, Helvetica, sans-serif'>HELLO WORLD <br />"
Massy Member Licensed User Longtime User Jun 21, 2014 #3 Thanks a lot for your help... problem is that I need to create the html based on some variables... so I can not just load a precompiled html... but your solution is working very good! Thanks again Massy Upvote 0
Thanks a lot for your help... problem is that I need to create the html based on some variables... so I can not just load a precompiled html... but your solution is working very good! Thanks again Massy
NJDude Expert Licensed User Longtime User Jun 21, 2014 #4 Actually you could, depending on how you are creating that HTML. Upvote 0
Massy Member Licensed User Longtime User Jun 21, 2014 #5 I have a template and in some parts I have to put my variables... something like: <td><div align='center'>Percentage =" & MyVariable & "</div></td> but it's just few days I'm coding with b4a and really don't know how else to achieve it... my idea is to first create all the html code in a variable and then save it as a html file and then load it in a webview... I'm sure there must be a better way to go... but don't know where to find it... if you have any input I will be all ears.... Upvote 0
I have a template and in some parts I have to put my variables... something like: <td><div align='center'>Percentage =" & MyVariable & "</div></td> but it's just few days I'm coding with b4a and really don't know how else to achieve it... my idea is to first create all the html code in a variable and then save it as a html file and then load it in a webview... I'm sure there must be a better way to go... but don't know where to find it... if you have any input I will be all ears....
warwound Expert Licensed User Longtime User Jun 21, 2014 #6 I'd suggest using a StringBuilder. Code: Copy Dim Html As StringBuilder Html.initialize Html.Append("<div>A hardcoded string</div>") Html.Append("<div>The variable value is: '") Html.Append(MyVariable) Html.Append("'.</div>") Dim MyString As String="to the " Html.Append("<div>You can chain calls ").Append(MyString).Append("Append method</div>") ' the StringBuilder .ToString method returns your 'built' String. Log(Html.ToString) ' load it into a WebView see http://www.b4x.com/android/help/views.html#webview_loadhtml MyWebView.LoadHtml(Html.ToString) Martin. Last edited: Jun 21, 2014 Upvote 0
I'd suggest using a StringBuilder. Code: Copy Dim Html As StringBuilder Html.initialize Html.Append("<div>A hardcoded string</div>") Html.Append("<div>The variable value is: '") Html.Append(MyVariable) Html.Append("'.</div>") Dim MyString As String="to the " Html.Append("<div>You can chain calls ").Append(MyString).Append("Append method</div>") ' the StringBuilder .ToString method returns your 'built' String. Log(Html.ToString) ' load it into a WebView see http://www.b4x.com/android/help/views.html#webview_loadhtml MyWebView.LoadHtml(Html.ToString) Martin.
NJDude Expert Licensed User Longtime User Jun 21, 2014 #7 Take a look at the attached sample, that will give you an idea. You can create your HTML using an HTML editor etc, will make your life easier. Attachments Quick_Sample.zip Quick_Sample.zip 11.3 KB · Views: 292 Upvote 0
Take a look at the attached sample, that will give you an idea. You can create your HTML using an HTML editor etc, will make your life easier.