Capitalise first letter of names (fred bloggs = Fred Bloggs)

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1049 Views - Last Post: 04 April 2013 - 11:33 AM Rate Topic: -----

#16 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • Joined: 29-May 08

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 03 April 2013 - 02:16 PM

Sidetracks are good.
JS is more functional then it is OO, i don't think C# is purely OO (as to compared to something like SmallTalk)
Was This Post Helpful? 0
  • +
  • -

#17 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,410
  • Joined: 12-December 12

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 03 April 2013 - 02:18 PM

View PostAdamSpeight2008, on 03 April 2013 - 09:16 PM, said:

Sidetracks are good.
JS is more functional then it is OO, i don't think C# is purely OO (as to compared to something like SmallTalk)

He, he! Opening a can of worms there I think :)
Was This Post Helpful? 0
  • +
  • -

#18 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • Joined: 29-May 08

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 03 April 2013 - 02:31 PM

I'm on about a slightly different use of Global.

I could add the extension in to System.String
Namespace Global.System.String
  <HideModuleName>
  Public Module Exts
    <Extension()>
    Public Function ToTitleCase(s As String) As String
      Return Application.CurrentCulture.TextInfo.ToTitleCase(s)
    End Function
  End Module
End Namespace



Quote

Can of Worms

Lets go fishing.
Was This Post Helpful? 0
  • +
  • -

#19 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,410
  • Joined: 12-December 12

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 03 April 2013 - 02:43 PM

@Adam Looks like that use of Global may not have an equivalent in C# (although I haven't dug very deep).
Was This Post Helpful? 0
  • +
  • -

#20 oyyou  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 184
  • Joined: 26-April 10

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 04 April 2013 - 12:54 AM

Oh man. I didn't expect this when I got back. Only blew 84% of my mind. Aha!
Was This Post Helpful? 0
  • +
  • -

#21 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4526
  • View blog
  • Posts: 7,894
  • Joined: 08-June 10

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 04 April 2013 - 11:18 AM

View Postandrewsw, on 03 April 2013 - 03:38 PM, said:

namespace ExtensionMethods {
    public static class MyExtensions {
        public static string TitleCase(this String str) {
            return String.Join(" ",(from word in str.Split(new char[]{' '},
                                                  StringSplitOptions.RemoveEmptyEntries)
                              select word[0].ToString().ToUpper() + word.Substring(1).ToLower()));
        }
    }
}

using ExtensionMethods;

namespace ConsTest {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("howdy doody!".TitleCase());
            
            Console.ReadKey();
        }
    }
}


Just throwing out an alternative LINQ way to do this, using the Aggregate method:

var input = "hello world this is a string";
var output = input.Split(' ')
         .Select(i => i.First().ToString().ToUpper() + i.Substring(1))
         .Aggregate((w, n) => w + " " + n);


Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,410
  • Joined: 12-December 12

Re: Capitalise first letter of names (fred bloggs = Fred Bloggs)

Posted 04 April 2013 - 11:33 AM

@Curtis Thank you (unable to rep you unfortunately.. my buttons don't work). I like LINQ - it's kinda cool :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2