替换“ - ”与大写字母 [英] Replace "-" with capital Letters

查看:222
本文介绍了替换“ - ”与大写字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用eyeOfTiger替换例如老虎眼,但我不知道解决方案。

I want to replace for example "eyes-of-tiger" with eyesOfTiger but I don't Know the exactly solution.

如何将 - 替换为大写字母?

How to replace "-" with capital Letters?

推荐答案

public class Test {

    public static void main(String[] args) {

        String input = "eye-of-tiger";
        String modified = dashToUpperCase(input);
        System.out.println(modified);
    }

    private static String dashToUpperCase(String input) {

        StringBuilder result = new StringBuilder();
        boolean toUpper = false;

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c == '-') {
                toUpper = true;
            } else {
                result.append(toUpper ? Character.toUpperCase(c) : c);
                toUpper = false;
            }
        }

        return result.toString();
    }
}

这篇关于替换“ - ”与大写字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆