p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 (http://p2p.wrox.com/forumdisplay.php?f=472)
-   -   Title.ToUrlFormat() (http://p2p.wrox.com/showthread.php?t=78988)

tedr April 13th, 2010 10:14 AM

Title.ToUrlFormat()
 
What is this code trying to do, Not sure I understand, was the string class overloaded to include a method ToUrlFormat(), if so where is it.

Title.ToUrlFormat().

if title is the Url why not just

Path = UrlEncode(title)

I still think I'm missing something, can this be explained [:confused:]

nberardi April 13th, 2010 10:17 AM

ToUrlFormat() makes the slug for the URL.

So if you have the following title

"How is my title goin' to be formatted for everybody."

it would get changed to

how-is-my-title-goin-to-be-formatted-for-everbody

Nick

tedr April 13th, 2010 10:37 AM

Title.ToUrlFormat()
 
Still not sure where the code is to that, it looks like it looks for the Url path.

Path = title.ToUrlFormat();

title is a string and there is not a method for string that match ToUrlFormat()[:confused:]

nberardi April 13th, 2010 11:04 AM

Read up on extension methods.

http://msdn.microsoft.com/en-us/library/bb383977.aspx

tedr April 13th, 2010 11:10 AM

extension mathods
 
I found this, is this what you mean by extension methods

public static class StringExtensions
{
private static readonly Regex UrlReplacementExpression = new Regex(@"[^0-9a-z \-]*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant);


/// <summary>
/// Toes the URL part.
/// </summary>
/// <param name="content">The content.</param>
/// <returns></returns>
public static string ToUrlFormat(this string content)
{
return UrlReplacementExpression.Replace(content.Trim(), String.Empty).Replace(' ', '-').ToLowerInvariant();
}[:confused:]

nberardi April 13th, 2010 11:12 AM

Try it out, and take a look at the link I sent you.

tedr April 13th, 2010 11:32 AM

The Link
 
OK I understand, what the link explains but I feels as if I'm still missing something, or maybe my problem was I was having trouble with the path in another program I was doing and was hoping this was my solution.

path = title.ToUrlFormat();

I read this as the title has the Url path in it, or is the Url path and that the ToUrlFormat is an extension method that will return that part of it, and if that is the case, what part of it was being done in the extension method.

this is great stuff and I appreciate all the help, I think I'm asking what others want to but not asking, or maybe this is just me. I hope I'm not being picky with this.[:I]

nberardi April 13th, 2010 11:37 AM

I don't understand your question.

tedr April 13th, 2010 11:51 AM

Question
 
I guess my question do you have source code where you have these extension methods that you use in the book?[:I]

nberardi April 13th, 2010 12:09 PM

You have the one above. That is all you need for ToUrlFormat()


All times are GMT -4. The time now is 11:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.