• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Is there any way to fit two long strings within two variables like below?

shahin

Active Member
Is it possible to make the two long strings (one contains Html document, another contains json data) fit within two variable "str" and "json_str" so that I can use them for practice? I tried with single quote, double quote and triple quote but that didn't work. Every time when I try to put those strings within the two variables I get errors. How can I fit them?

Erroneous approach:

Code:
Sub Demo()
    str = <h3><a href="/questions/" class="question">when used in a UDF</a></h3>
    json_str = {"totalCount":431,"messages":[],"results":[{"aliasList":["User Id","Name","last name"],"results":[[71512,"joe","adams"],[23445,"jack","wilson"],[34566,jill,goodman]],"executionDate":151134568428}],"Class":"com.zoho.controlpanel.reports.ReportsItemVO"}
End Sub

Any help to fix this will be highly appreciated.
 
@sir Hui, this is so damn great!!!! Highly appreciated. The solution is applicable for the json string as well. Thankssssssssss again.
 
Whoops, it should be "" not """

ie:
Code:
Sub Demo()
   
    Str1 = "<h3><a href=""/questions/"" class=""question"">when used in a UDF</a></h3>"
    Debug.Print Str1
   
    json_str = "{""totalCount"":431,""messages"":[],""results"":[{""aliasList"":[""User Id"",""Name"",""last name""],""results"":[[71512,""joe"",""adams""],[23445,""jack"",""wilson""],[34566,jill,goodman]],""executionDate"":151134568428}],""Class"":""com.zoho.controlpanel.reports.ReportsItemVO""}"
    Debug.Print json_str
   
    'Original String
    'str1 = <h3><a href="/questions/" class="question">when used in a UDF</a></h3>
    'json_str = {"totalCount":431,"messages":[],"results":[{"aliasList":["User Id","Name","last name"],"results":[[71512,"joe","adams"],[23445,"jack","wilson"],[34566,jill,goodman]],"executionDate":151134568428}],"Class":"com.zoho.controlpanel.reports.ReportsItemVO"}

End Sub
 
This is why I was trying so:
Code:
Sub Demo()
    Dim HTML As New HTMLDocument, post As Object
   
    HTML.body.innerHTML = "<h3><a href=""/questions/"" class=""question"">when used in a UDF</a></h3>"
   
    Set post = HTML.getElementsByTagName("a")(0)
    MsgBox post.innerText
End Sub
 
Back
Top