Replacing char

A

anonymous

Hello,

I need to replace this char  with another char.
However I am not able to acieve this. I tried this but it
doesnt work:

str = str.Replace(chr(asc(194)), "")

Can somebody help ?
 
G

Guest

The "replace" needs either two characters or two strings. In your case, try:

Dim c As Char = Chr(194)
str = str.Replace(c.ToString, "")

Or why not just str.replace("Â", "")?

Bill
 
A

anonymous

I tried both versions, but it still doesnt work. The thing
is that I am reading the following rss
(http://pluralsight.com/blogs/dbox/Rss.aspx) and creating
the file with the description of the item. The file
contains only the description with the strange chars. Here
is my complete code:

Dim reader As New XmlTextReader
("http://pluralsight.com/blogs/dbox/Rss.aspx")
Dim xmlDoc As New XmlDocument

xmlDoc.Load(reader)

Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")
dim i as integer = 0

For Each node As XmlNode In nodes
Try
strPost = node("description").InnerXml
Dim c as char = Chr(194)
strPost = strPost.Replace("Â", "XX")
Dim fp As StreamWriter
dim strfile as string = Server.MapPath("xml_news//")
strfile = strfile & i.tostring()
strfile = strfile & ".asp"
fp = File.CreateText(strfile)
fp.WriteLine("<p>" & Server.HtmlDecode(strPost)
& "</p>")
fp.close()
Catch ex As Exception
Response.Write(ex.Message() & "<br>")
End Try
i = i + 1
Next

Thanks for any help.
 
M

mortb

I don't see any Âs in the feed? Is it really the character you want to
replace?
cheers,
mortb

I tried both versions, but it still doesnt work. The thing
is that I am reading the following rss
(http://pluralsight.com/blogs/dbox/Rss.aspx) and creating
the file with the description of the item. The file
contains only the description with the strange chars. Here
is my complete code:

Dim reader As New XmlTextReader
("http://pluralsight.com/blogs/dbox/Rss.aspx")
Dim xmlDoc As New XmlDocument

xmlDoc.Load(reader)

Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")
dim i as integer = 0

For Each node As XmlNode In nodes
Try
strPost = node("description").InnerXml
Dim c as char = Chr(194)
strPost = strPost.Replace("Â", "XX")
Dim fp As StreamWriter
dim strfile as string = Server.MapPath("xml_news//")
strfile = strfile & i.tostring()
strfile = strfile & ".asp"
fp = File.CreateText(strfile)
fp.WriteLine("<p>" & Server.HtmlDecode(strPost)
& "</p>")
fp.close()
Catch ex As Exception
Response.Write(ex.Message() & "<br>")
End Try
i = i + 1
Next

Thanks for any help.
 
G

Guest

I get exceptions when I run your code ("could not find a part of the path"),
but tracing through still don't see the  (e.g. strPost.IndexOf("Â") fails).
Is it possible you have a code page problem?

Bill
 
A

Anonymous

The A character only appear in the created file. Ofcourse
you need the change the path so that it works on your
system.

Please help.


-----Original Message-----
I get exceptions when I run your code ("could not find a part of the path"),
but tracing through still don't see the Ã, (e.g.
strPost.IndexOf("Ã,") fails).
 
G

Guest

My dumb mistake on the path. Looks like the source has some nonbreaking
spaces ( ascii 160), which the htmldecode is turning into asc 194. I'm
guessing you could do your replace *after* the decode, else replace on 160
*before* the decode. As to why that space is not encoded, whereas, say, the
<'s are correctly converted to < etc., I don't know. Not sure if that happens
on the rss end, or maybe in your textreader. Anyway, I'm not familiar with
grabbing a feed the way you're doing it, so can't offer much more. Hopefully
this will get you going.

Bill
 
A

Anonymous

Thanks man. That did the trick. I was replacing 194 before
encoding. Now I am replacing 160 before encoding and it
works like a charm. How did you know that it 160 before
encoding?

Thanks
 
G

Guest

I just looked at the 194's, then went back to those same positions in the
original and found the 160's by dumping the ascii values of those strings. I
had also guessed it might be something with &nbsp's, which is always a decent
bet when something looks ok on the screen but your code chokes on it. Have
fun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top