Results 1 to 12 of 12

Thread: listview characters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    listview characters

    Hi,

    i am using Microsoft.XMLHTTP to pull information from a php page on my server, and they look exactly how they should look via firefox webbrowser, but via Microsoft.XMLHTTP outputted to a Listview the special characters aren't formmated correctly.

    eg,

    & #39; (had to put a space after & as it turns into a apostrophe on the site)

    instead of

    '

    This is a encoding issue? how do i encode it to utf-8 if this is the case?

    thanks in advance

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: listview characters

    & #39; is an HTML character code, not an encoding issue... you'll probably need a regular expression, like so:
    Code:
    Dim re As New System.Text.RegularExpressions.Regex("&#(\d+);", System.Text.RegularExpressions.RegexOptions.SingleLine)
    Then you can match it with each string you're outputting and access the code:
    Code:
    For Each m As System.Text.RegularExpressions.Match In re.Match(my string)
         Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
         Dim chr As Char = AscW(cc)
         (my string) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
    Next
    You've got to take into account things like ' too, though.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    vb Code:
    1. For Each m As System.Text.RegularExpressions.Match In re.Match(my string)
    2.      Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
    3.      Dim chr As Char = AscW(cc)
    4.      (my string) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
    5. Next

    ok this is good, but when i put string into "my string" it states "cannot be converted to -1 dimension bla bla"

    this is the changed code
    vb Code:
    1. Dim download_list() As String
    2.         download_list = Split(listmain, "<##>")
    3.  
    4.         For Each line As String In download_list
    5.             'if line is null, skip it
    6.             If line = vbNullString Then Exit For
    7.             'Dim info As New UserControl1()
    8.             Dim values() As String
    9.             values = Split(line, "<**>")
    10.  
    11. For Each m As System.Text.RegularExpressions.Match In re.Match(values)
    12.      Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
    13.      Dim chr As Char = AscW(cc)
    14.      (values) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
    15. Next
    16.  
    17.             Dim str(3) As String
    18.             Dim itm As ListViewItem
    19.             str(0) = values(2)
    20.             str(1) = values(1)
    21.             str(2) = values(3)
    22.  
    23.             itm = New ListViewItem(str)

    whats the correct syntax for multiple values?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    i just also tried it before the splitting so its all one string still like so:

    vb Code:
    1. listmain = oHTTP.responseText
    2.  
    3.  
    4.         For Each m As System.Text.RegularExpressions.Match In re.Match(listmain)
    5.             Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
    6.             Dim chr As Char = AscW(cc)
    7.             listmain = (listmain).Remove(m.Index, m.Length).Insert(m.Index, chr)
    8.         Next

    still dont work, gives error:

    Expression is of type 'System.Text.RegularExpressions.Match', which is not a collection type.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    i have done it now, like this (it replaces the most common characters):

    Please tell me if there is an easier (more smaller/simpler way .
    PHP Code:
    listmain oHTTP.responseText

            listmain 
    Regex.Replace(listmain"&amp;""&")
            
    listmain Regex.Replace(listmain"&apos;""'")
            
    listmain Regex.Replace(listmain" "" ")
            
    listmain Regex.Replace(listmain"!""!")
            
    listmain Regex.Replace(listmain""""'")
            
    listmain Regex.Replace(listmain"#""#")
            
    listmain Regex.Replace(listmain"$""$")
            
    listmain Regex.Replace(listmain"%""%")
            
    listmain Regex.Replace(listmain"&""&")
            
    listmain Regex.Replace(listmain"'""'")
            
    listmain Regex.Replace(listmain"(""(")
            
    listmain Regex.Replace(listmain")"")")
            
    listmain Regex.Replace(listmain"*""*")
            
    listmain Regex.Replace(listmain"+""+")
            
    listmain Regex.Replace(listmain","",")
            
    listmain Regex.Replace(listmain"-""-")
            
    listmain Regex.Replace(listmain"."".")
            
    listmain Regex.Replace(listmain"/""/")
            
    listmain Regex.Replace(listmain":"":")
            
    listmain Regex.Replace(listmain";"";")
            
    listmain Regex.Replace(listmain"<""<")
            
    listmain Regex.Replace(listmain"=""=")
            
    listmain Regex.Replace(listmain">"">")
            
    listmain Regex.Replace(listmain"?""?")
            
    listmain Regex.Replace(listmain"@""@")
            
    listmain Regex.Replace(listmain"[""[")
            
    listmain Regex.Replace(listmain"\""\")
            listmain = Regex.Replace(listmain, "
    ]", "]")
            listmain = Regex.Replace(listmain, "
    &#94;", "^")
            
    listmain Regex.Replace(listmain"_""_")
            
    listmain Regex.Replace(listmain"{""{")
            
    listmain Regex.Replace(listmain"|""|")
            
    listmain Regex.Replace(listmain"}""}")
            
    listmain Regex.Replace(listmain"~""~")
            
    listmain Regex.Replace(listmain"¡""¡")
            
    listmain Regex.Replace(listmain"¢""¢")
            
    listmain Regex.Replace(listmain"£""£")
            
    listmain Regex.Replace(listmain"¤""¤")
            
    listmain Regex.Replace(listmain"¥""¥")
            
    listmain Regex.Replace(listmain"¦""¦")
            
    listmain Regex.Replace(listmain"§""§")
            
    listmain Regex.Replace(listmain"¨""¨")
            
    listmain Regex.Replace(listmain"©""©")
            
    listmain Regex.Replace(listmain"ª""ª")
            
    listmain Regex.Replace(listmain"«""«")
            
    listmain Regex.Replace(listmain"¬""¬")
            
    listmain Regex.Replace(listmain"®""®")
            
    listmain Regex.Replace(listmain"¯""¯")
            
    listmain Regex.Replace(listmain"°""°")
            
    listmain Regex.Replace(listmain"±""±")
            
    listmain Regex.Replace(listmain"´""´")
            
    listmain Regex.Replace(listmain"·""·")
            
    listmain Regex.Replace(listmain"»""»")
            
    listmain Regex.Replace(listmain"¿""¿")
            
    listmain Regex.Replace(listmain"&#x22;""\")
            listmain = Regex.Replace(listmain, "
    &#x2039;", "<")
            
    listmain Regex.Replace(listmain"&#x203A;"">")
            
    listmain Regex.Replace(listmain"&gt;"">=")
            
    listmain Regex.Replace(listmain"&lt;""<="
    This should come to some use for someone alse also with same problem.

    EDIT: cannot get it to show as characters are being converted when submitted :/ you get the idea anyway.
    Last edited by vistar86; Aug 2nd, 2010 at 08:56 AM.

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: listview characters

    What in the world is that code supposed to do???! The problem with when you replaced "my string" is that you kept the parenthesis. Delete them.

    What your code is currently doing is replacing a few characters with themselves using Regex. That is 100&#37; bad coding and useless. Remove it!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    no the forums here re-encodes the html special characters so does not look like above, an example of how the above should look:

    vb Code:
    1. listmain = Regex.Replace(listmain, "& #35;", "#")

    and so on...

    had to put a space after & because like i say it convertes the characters on this forum.

    I know i dont even need regex, only replace would work.

    oh and if your solution worked id have used that, but you see here is the code and i dont put parenthesis, and get the error look:

    Dim values() As String
    values = Split(line, "<**>")

    vb Code:
    1. For Each m As System.Text.RegularExpressions.Match In re.Match(values)
    2.  
    3.      Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
    4.  
    5.      Dim chr As Char = AscW(cc)
    6.  
    7.      (values) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
    8.  
    9. Next
    Last edited by vistar86; Aug 2nd, 2010 at 11:43 AM.

  8. #8
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: listview characters

    Look, you're doing it completely wrong. What I gave you originally is the easiest solution. Just take out the parenthesis.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    Where's the parethesis??

    vb Code:
    1. Dim re As New System.Text.RegularExpressions.Regex("&#(\d+);", System.Text.RegularExpressions.RegexOptions.SingleLine)
    2.  
    3.         For Each line As String In download_list
    4.             'if line is null, skip it
    5.             If line = vbNullString Then Exit For
    6.             Dim values() As String
    7.             values = Split(line, "<**>")
    8.  
    9.      For Each m As System.Text.RegularExpressions.Match In re.Match(values)
    10.  
    11.            Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
    12.  
    13.            Dim chr As Char = AscW(cc)
    14.  
    15.            (values) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
    16.  
    17.       Next
    18.  
    19.           Dim str(3) As String
    20.             Dim itm As ListViewItem
    21.             str(0) = values(2)
    22.             str(1) = values(1)
    23.             str(2) = values(3)
    24.  
    25.             itm = New ListViewItem(str)

  10. #10
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: listview characters

    Here is your code, fixed:
    Code:
    Dim re As New System.Text.RegularExpressions.Regex("&#(\d+);", System.Text.RegularExpressions.RegexOptions.SingleLine)
             For Each line As String In download_list
                Dim values() As String
                values = Split(line, "<**>")
                For Each m As System.Text.RegularExpressions.Match In re.Match(values)
                   Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
                   Dim chr As Char = AscW(cc)
                   line = line.Remove(m.Index,m.Length).Insert(m.Index,chr)
                Next
                Dim str(3) As String
                Dim itm As ListViewItem
                str(0) = values(2)
                str(1) = values(1)
                str(2) = values(3)
                 itm = New ListViewItem(str)

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    89

    Re: listview characters

    still says an error on the:

    vb Code:
    1. In re.Match(values)

    Value of type '1-dimensional array of String' cannot be converted to 'String'.

  12. #12
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: listview characters

    Ah OK, you weren't supposed to replace it with that. By (my string) I meant the actual string. Use this:
    Code:
    Dim re As New System.Text.RegularExpressions.Regex("&#(\d+);", System.Text.RegularExpressions.RegexOptions.SingleLine)
             For Each line As String In download_list
                For Each m As System.Text.RegularExpressions.Match In re.Match(line)
                   Dim cc As Integer = Integer.Parse(re.Groups(1).Value)
                   Dim chr As Char = AscW(cc)
                   line = line.Remove(m.Index,m.Length).Insert(m.Index,chr)
                Next
                Dim values() As String
                values = Split(line, "<**>")
                Dim str(3) As String
                Dim itm As ListViewItem
                str(0) = values(2)
                str(1) = values(1)
                str(2) = values(3)
                 itm = New ListViewItem(str)
    I also don't recommend using the VB6 Split() function. But it doesn't make a difference anyways.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width