Forum Moderators: open

Message Too Old, No Replies

Removing %20 and replace with space

         

dertyfern

11:16 am on Mar 10, 2010 (gmt 0)

10+ Year Member



I'm trying to replace "%20" with " " (that's a blank space) when I click on an imagebutton to post an article to twitter.

Problem is that when logging on to twitter to post the tweet, I can't get the .net (c#) code to replace "%20" with a blank space so as to separate words in a phrase.

I'm using the following code to replace:

string sm_title = Rdr.GetString(1).ToString().Replace("%20", " ");

Have tried:

string sm_title = Rdr.GetString(1).ToString().Replace("%20", " ");

and others.

I've also tried replacing at the imagebutton too...not working.

Thanks for any help.

marcel

1:08 pm on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would have expected the string.Replace method to work, it works in a simple test I did here.

Another option is to decode the string:
string sm_title = Server.UrlDecode(Rdr.GetString(1).ToString());

dertyfern

1:40 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



I also find it strange that string.Replace doesn't work.

Tried
string sm_title = Server.UrlDecode(Rdr.GetString(1).ToString());
but that doesn't seem to do it either.

StoutFiles

1:53 pm on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



string sm_title = Rdr.GetString(1).ToString().Replace("%20", " ");


So when you print out sm_title after this the %20 is still there? Just wondering if the function is working but the posting is putting the %20 back in.

dertyfern

2:03 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



StoutFiles, that's exactly right. I'm wondering the same about the posting. Perhaps changing the control to a hyperlink control would help?

dertyfern

2:34 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



Solved it. Twitter treats the plus sign as a space so I:

string sm_title = Rdr.GetString(1).ToString().Replace("%20", "+");

dstiles

10:34 pm on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Spaces in filenames have always caused problems, especially on the internet. I always replace them with either hyphen, underscore or word-capitalising. Saves endless messing about.