My first foray into Code Golf

So I am poking around on Stack Overflow, trying to figure out a way for someone as stupid as me to actually move my reputation up, when I stumble on this post…

Code Golf: Duplicate Character Removal in String (EDIT: Sorry, I had to remove the link as the question was removed by Stack Overflow…)

This seemed simple enough, so here is my VB.NET console application code:

Module Module1

    Sub Main()

        Dim s As String = "nbHHkRvrXbvkn"
        Console.WriteLine("The original string is: " + s)
        For Each c In s : s = IIf(s.LastIndexOf(c) <> s.IndexOf(c), s.Replace(CStr(c), Nothing), s) : Next
        Console.WriteLine("The modified string is: " + s)
        Console.ReadKey()

    End Sub

End Module

The line that does all the work is 98 characters, including the spaces that the IDE automagically puts in there for me.

Anyone have any ideas on how to improve it in VB.NET?

2 thoughts on “My first foray into Code Golf”

  1. Hey John, the ocean called, they’re running out of shrimp.

    You know, you could always go over to Stack Overflow and upvote my answer.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.