Search code examples
powershellasp.net-mvc-scaffolding

CamelCase a word in Powershell / Templates


I've looked everywhere and I can't seem to find an answer, maybe because I don't know enough to know what to search for.

I've used the Get-PluralizedWord function.

Is there a similar way to convert a given word like MyClass, to myClass in powershell/T4Templates ?

Cheers,

James


Solution

  • To convert a given word like MyClass to myClass, you can use a .net regex replace:

    [Regex]::Replace("MyClass" , '\b.', {  $args[0].Value.Tolower() })
    

    or substring manipulation:

    "MyClass" | % { $_.substring(0,1).tolower()+$_.substring(1) }