驼峰转下划线各种方式, 总有一个你工作中需要的

本文介绍了如何在Excel中使用宏和函数实现字符串的驼峰命名(如xVAT转为x_v_a_t)和下划线命名(如x_v_a_t转为x_v_a_t)的转换,包括正则表达式方法和逐字符处理的方法。
摘要由CSDN通过智能技术生成

idea驼峰下划线转换

模式串

(\w*)_(\w*)

捕获组加大写转换

\$1\u$2

说明: $1表示第一个捕获组, $0便是这个字符串, \u是下一个字符转化成大写, 对应的\l是小写

excel驼峰转下划线[宏命令]

Sub CamelToUnderline()
Dim c As Range
For Each c In Selection
Dim result As String
result = “”
Dim str As String
str = c.Value
For i = 1 To Len(str)
Dim currentLetter As String
currentLetter = Mid(str, i, 1)
If i = 1 Then
result = result & LCase(currentLetter)
ElseIf currentLetter = UCase(currentLetter) Then
result = result & “_” & LCase(currentLetter)
Else
result = result & currentLetter
End If
Next i
c.Value = result
Next c
End Sub

说明: xVAT会被转换成x_v_a_t, 使用是有可以注意一下, 自己也可以修改下算法针对性兼容, 不过感觉没有必须, 有这种数据场景应该不多

excel下划线转驼峰[函数]

=LOWER(LEFT(SUBSTITUTE(PROPER(A1),"_",""),1))&RIGHT(SUBSTITUTE(PROPER(A1),"_",""),LEN(SUBSTITUTE(PROPER(A1),"_",""))-1)

或者这样
=LEFT(A1,1)&MID(SUBSTITUTE(PROPER(A1),"_",""),2,100)

excel下划线转驼峰[宏]

Sub UnderlineToCamel()
    Dim cell As Range
    For Each cell In Selection
        cell.Value = WorksheetFunction.Proper(Replace(cell.Value, "_", " "))
        cell.Value = Replace(cell.Value, " ", "")
    Next cell
End Sub
  • 16
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岁月玲珑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值