问题描述
我想将 VSCode Dart 代码段中的第一个大写字母转换为小写.
I would like to convert the first uppercased letter in a VSCode Dart snippet to a lowercased one.
示例:
MyClassIWroteInMySnippet -> myClassIWroteInMySnippet
在我的搜索过程中,我发现了 this 演示了如何将 camelCase 字符串转换为 UPPER_CASED_STRING 但我没有选择第一个字符(大写)然后将其转换为小写...
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...
任何帮助都会非常感激!
谢谢:)
这是我当前的片段
"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"
},
因此,如果我插入我的代码段,并编写MyClass",我想在我的代码中显示
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();
推荐答案
在你澄清问题后,试试这个:
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/}
将第一个字母放入捕获组 1,其余放入捕获组 2.然后第一个字母是小写的,第二组附加在后面.
${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.
这篇关于VSCode 片段将第一个大写字母转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!