C# razor replace string

Hi guys,

I'm updating an old site into C# Razor, and the links have a URL rewrite function in place using global.asax.

On the old site we have the following code rewriting the URL using the title in the database:

<a href="newsitem/<%= replace(replace(rsNews("title")," ", "_"), "/", "(slash)") %>.html" title="<%=rsNews("Title")%>"><%=rsNews("Title")%></a>

Open in new window

Is there an equivalent to this using C# Razor? Any help/pointers would be much appreciated!
Who is Participating?
replace(rsNews("title")," ", "_")


rsNews("title").Replace(" ","_");

and then

replace(replace(rsNews("title")," ", "_"), "/", "(slash)")


rsNews("title").Replace(" ","_").Replace("/", "(slash"));


rsNews("title") is an instance of string class. string has Replace method. And since rsNews("title") is also a string we can use it's replace method.
RossLiversidgeAuthor Commented:
Absolutely spot on.

For reference, in Razor I set the code as follows:

<a href="@row.Title.Replace(" ","_").Replace("/", "(slash")).html">
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.