Answer a question

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();

Answers

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.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐