|
-
Aug 1st, 2010, 04:54 PM
#1
Thread Starter
Lively Member
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
-
Aug 1st, 2010, 06:56 PM
#2
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.
-
Aug 2nd, 2010, 03:10 AM
#3
Thread Starter
Lively Member
Re: listview characters
vb 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
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:
Dim download_list() As String download_list = Split(listmain, "<##>") For Each line As String In download_list 'if line is null, skip it If line = vbNullString Then Exit For 'Dim info As New UserControl1() 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) (values) = (my string).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)
whats the correct syntax for multiple values?
-
Aug 2nd, 2010, 03:13 AM
#4
Thread Starter
Lively Member
Re: listview characters
i just also tried it before the splitting so its all one string still like so:
vb Code:
listmain = oHTTP.responseText For Each m As System.Text.RegularExpressions.Match In re.Match(listmain) Dim cc As Integer = Integer.Parse(re.Groups(1).Value) Dim chr As Char = AscW(cc) listmain = (listmain).Remove(m.Index, m.Length).Insert(m.Index, chr) Next
still dont work, gives error:
Expression is of type 'System.Text.RegularExpressions.Match', which is not a collection type.
-
Aug 2nd, 2010, 08:52 AM
#5
Thread Starter
Lively Member
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, "&", "&")
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, "]", "]")
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, """, "\")
listmain = Regex.Replace(listmain, "‹", "<")
listmain = Regex.Replace(listmain, "›", ">")
listmain = Regex.Replace(listmain, ">", ">=")
listmain = Regex.Replace(listmain, "<", "<=")
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.
-
Aug 2nd, 2010, 10:35 AM
#6
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% bad coding and useless. Remove it!
-
Aug 2nd, 2010, 11:35 AM
#7
Thread Starter
Lively Member
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:
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:
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)
(values) = (my string).Remove(m.Index,m.Length).Insert(m.Index,chr)
Next
Last edited by vistar86; Aug 2nd, 2010 at 11:43 AM.
-
Aug 2nd, 2010, 11:42 AM
#8
Re: listview characters
Look, you're doing it completely wrong. What I gave you originally is the easiest solution. Just take out the parenthesis.
-
Aug 2nd, 2010, 11:44 AM
#9
Thread Starter
Lively Member
Re: listview characters
Where's the parethesis??
vb Code:
Dim re As New System.Text.RegularExpressions.Regex("&#(\d+);", System.Text.RegularExpressions.RegexOptions.SingleLine) For Each line As String In download_list 'if line is null, skip it If line = vbNullString Then Exit For 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) (values) = (my string).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)
-
Aug 2nd, 2010, 08:14 PM
#10
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)
-
Aug 3rd, 2010, 02:36 AM
#11
Thread Starter
Lively Member
Re: listview characters
still says an error on the:
Value of type '1-dimensional array of String' cannot be converted to 'String'.
-
Aug 4th, 2010, 01:10 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|