How can I swap uppercase and lowercase alternatively?

前端 未结 2 1037
小蘑菇
小蘑菇 2021-01-16 12:10

I\'m writing a program that can convert uppercase into lowercase and lowercase into uppercase alternatively. Here are some examples.

abcde -> aBcDe

2条回答
  •  爱一瞬间的悲伤
    2021-01-16 13:02

    You didn't say what shell you want to use. Depending on the shell, this can be complicated or easy.

    For example, in Zsh, it is very easy:

    myvar="abcd"
    myvar_uppercase=${(U)myvar}
    

提交回复
热议问题