1

I would like to convert the first uppercased letter in a VSCode Dart snippet to a lowercased one.

Example:

MyClassIWroteInMySnippet -> myClassIWroteInMySnippet

During my search, I found this which demonstrate how to convert a camelCase String to UPPER_CASED_STRING but I don't achieve to pick the first character (in uppercase) and then transform it to lowercase...

Any help would be very appreciated !

Thanks :)

EDIT:

Here is my current snippet

"Mock a service using Mockito": {
    "prefix": "testMockitoService",
    "body": [
        "class _${1}Mock extends Mock implements ${1} {}",
        "",
        "final ${1} = _${1}Mock();", // Here I want to "${1}" be camelCased when I finish to write my class
    ],
    "description": "Mock a service using Mockito"
},

So If I insert my snippet, and write "MyClass", I want to display in my code

class _MyClassMock extends Mock implements MyClass {}

final myClass = _MyClassMock();
iStornZ
  • 603
  • 1
  • 8
  • 19

1 Answers1

3

After your clarification in the question, try this:

  "Mock a service using Mockito": {
    "prefix": "testMockitoService",
    "body": [
        "class _${1}Mock extends Mock implements ${1} {}",
        "",
        "final ${1/(.)(.*)/${1:/downcase}$2/} = _${1}Mock();",
    ],
    "description": "Mock a service using Mockito"
  },

${1/(.)(.*)/${1:/downcase}$2/} puts the first letter into capture group 1 and the rest into capture group 2. Then that first letter is down-cased and the second group appended to that.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • Thanks for your answer, but it's not exactly what I search. I want to write my UPPERCASE word and when it's done, then convert the first letter to downcase. I edited my post for more info. Thanks again for your help! – iStornZ Oct 08 '20 at 08:08
  • 1
    You are awesome ! This is perfectly what I'm looking for thanks again ! – iStornZ Oct 08 '20 at 08:24