如何将虚线转换为camelcase

时间:2015-09-22 22:22:57

标签: excel excel-vba vba

有没有办法转换

my-dashed-word

myDashedWord
在Excel中

5 个答案:

答案 0 :(得分:4)

试试这个小 UDF()

Public Function DashFixer(inpt As String) As String
   If inpt = "" Then
      DashFixer = ""
      Exit Function
   End If

   ary = Split(inpt, "-")
   For i = LBound(ary) + 1 To UBound(ary)
      ary(i) = Application.WorksheetFunction.Proper(ary(i))
   Next i
   DashFixer = Join(ary, "")
End Function

enter image description here

答案 1 :(得分:3)

其他版本:

Public Function dCam(ByRef cel As String) As String

    dCam = Replace(StrConv(Replace(cel, "-", " "), vbProperCase), " ", "")  'MyDashedWord

    dCam = LCase(Left(dCam, 1)) & Right(dCam, Len(dCam) - 1)                'myDashedWord

End Function
=SUBSTITUTE(PROPER(A1),"-","") 'MyDashedWord

=LEFT(A1) & RIGHT(SUBSTITUTE(PROPER(A1),"-",""),LEN(SUBSTITUTE(A1,"-",""))-1) 'myDashedWord

答案 2 :(得分:2)

还有一个版本。

Dashed Word Extraction

B2中的公式是,

=LEFT(A2, FIND("-", A2&"- ")-1)&SUBSTITUTE(PROPER(MID(A2, FIND("-", A2&"- ")+1, 255)), "-", "")

答案 3 :(得分:1)

我想只有VBA对你来说是实用的,但有一个公式,复制到:

=SUBSTITUTE(A1,MID(A1,FIND("-",A1),2),UPPER(MID(A1,FIND("-",A1)+1,1)))

答案 4 :(得分:1)

没有像我希望的那样高效,因为没有办法按照

的方式进行一次替换。
.Pattern = "\-([a-z)([a-z]+)"
Set objRegexMC = .Replace(strIn, UCase("$1") & "$2")

但是我确实在那里用RegExp去了那里。

Function StrCon1(strIn As String) As String
Dim objRegex As Object
Dim objRegexMC As Object
Dim objRegexM As Object

Set objRegex = CreateObject("vbscript.regexp")
With objRegex
    .Global = True
    .Pattern = "\-([a-z])([a-z]+)"
Set objRegexMC = .Execute(strIn)
For Each objRegexM In objRegexMC
    strIn = Replace(strIn, objRegexM,UCase$(objRegexM.submatches(0)) & objRegexM.submatches(1))
Next
End With

StrCon1 = strIn
End Function