Java Char Convert To charToUpperOrLower(String string, int pos, boolean upper)

Here you can find the source of charToUpperOrLower(String string, int pos, boolean upper)

Description

Puts the given char to upper (true) or lower (false) case

License

Apache License

Parameter

Parameter Description
string a parameter
pos a parameter
upper if set to true, the char is set to upper case; if set to false, the char is set to lower case

Declaration

public static String charToUpperOrLower(String string, int pos, boolean upper) 

Method Source Code

//package com.java2s;
/**//w w  w.  j a v a  2  s  . c om
 * Copyright 2015 SPeCS Research Group.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License. under the License.
 */

public class Main {
    /**
     * Puts the given char to upper (true) or lower (false) case
     * 
     * @param string
     * @param pos
     * @param upper
     *            if set to true, the char is set to upper case; if set to false, the char is set to lower case
     * @return
     */
    public static String charToUpperOrLower(String string, int pos, boolean upper) {
        if (pos < 0 || pos >= string.length()) {
            throw new StringIndexOutOfBoundsException(pos);
        }
        String ret = string.substring(0, pos);
        if (upper) {
            ret += string.substring(pos, pos + 1).toUpperCase();
        } else {
            ret += string.substring(pos, pos + 1).toLowerCase();
        }
        ret += string.substring(pos + 1);
        return ret;
    }
}

Related

  1. charToLowerCase(char c)
  2. charToNCRef(int c)
  3. charToNum(char c)
  4. charToNybble(char c)
  5. charToOctet(char c)
  6. convertChar(char c)
  7. convertCharacter(final String value)
  8. convertCharacterEntity(String value)
  9. convertCharacterOffsetToCodePointOffset(String inputStr, int charOffset)