I have been asked on the BBS how I pulled reddit links into the BBS for callers to see. As you might know, I have been using RMLib to make some simple door utilities with C#.

My latest utility pulls some headlines from reddit, as well as showing recent activity on the board.

Here is the code that does this… I don’t want to release the full program source yet, as it has other stuff I need to finish up. Sorry.
Using this though you should be able to get a C# door running with RMLib.


WebClient w = new WebClient();
            string s = w.DownloadString("http://www.reddit.com/r/tech");
            string cleanString = "";
            string cleanURL = "";

            foreach (LinkItem i in LinkFinder.Find(s))
            {
                cleanString = Regex.Replace(i.Text.ToString(), @"[^\u0000-\u007F]", string.Empty);
                cleanURL = Regex.Replace(i.Href.ToString(), @"[^\u0000-\u007F]", string.Empty);
                Door.WriteLn(StringUtils.PadRight(cleanString, ' ', 57) + " | ");
                Door.WriteLn(StringUtils.PadRight(cleanURL, ' ', 57) + " | ");
                Door.WriteLn(StringUtils.PadRight(" ", ' ', 57) + " | ");
            }

---

public struct LinkItem
        {
            public string Href;
            public string Text;

            public override string ToString()
            {
                return Text + Href;
            }
        }

static class LinkFinder
        {
            public static List Find(string file)
            {
                List list = new List();
                int j = 0;

                MatchCollection m1 = Regex.Matches(file, @"(.*?)", RegexOptions.Singleline);

                foreach (Match m in m1)
                {
                    if (j <= 6)
                    {
                        string value = m.Groups[1].Value;
                        LinkItem i = new LinkItem();

                        Match m2 = Regex.Match(value, @"href=\""(.*?)\""", RegexOptions.Singleline);
                        if (m2.Success)
                        {
                            i.Href = m2.Groups[1].Value;

                        }

                        string t = Regex.Replace(value, @"\s*<.*?>\s*", "", RegexOptions.Singleline);
                        i.Text = t;

                        list.Add(i);
                        j++;
                    }
                }

                j = 0;
                return list;
            }
        }