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!
RossLiversidgeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

unknown_routineCommented:
replace(rsNews("title")," ", "_")

becomes:


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


and then

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

becomes:

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


Explanation:

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RossLiversidgeAuthor Commented:
Absolutely spot on.

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

<a href="@row.Title.Replace(" ","_").Replace("/", "(slash")).html">
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.