java 大小写转换函数

Given a string and we have to convert it from uppercase to lowercase.

给定一个字符串,我们必须将其从大写转换为小写。

Examples:

例子:

    Input:
IncludeHelp.com
Output:
includehelp.com
Input:
[email protected]
Output:
[email protected]

大写到小写转换 (Uppercase to lowercase conversion)

To convert an uppercase alphabet to lowercase alphabet – we can add 32 in uppercase alphabet's ASCII code to make it a lowercase alphabet (because the difference between a lowercase alphabet ASCII and an uppercase alphabet ASCII is 32).

要将大写字母转换为小写字母 –我们可以在大写字母的ASCII代码中添加32 ,以使其成为小写字母(因为小写字母ASCII和大写字母ASCII之间的差是32 )。

In the below code, we created a user-defined function UpperToLower() that will accept a string and returns string having lowercase characters. To convert uppercase alphabets of the string to lowercase alphabets, we are extracting characters one by one from the string using String.charAt() function and checking whether the character is an uppercase alphabet, if it is an uppercase alphabet, we are adding 32 to make it lowercase, else no change. Thus, only uppercase alphabets will be converted to lowercase alphabets, the rest of the characters like lowercase alphabets, digits and special characters will remain the same.

在下面的代码中,我们创建了一个用户定义的函数UpperToLower() ,该函数将接受一个字符串并返回包含小写字母的字符串。 要将字符串的大写字母转换为小写字母 ,我们使用String.charAt()函数从字符串中逐个提取字符,并检查字符是否为大写字母,如果是大写字母,则将32加到将其设置为小写,否则将保持不变。 因此,只有大写字母将转换为小写字母,其余字符(如小写字母,数字和特殊字符)将保持不变。

大写到小写转换的Java代码 (Java code for uppercase to lowercase conversion)

// Uppercase to lowercase conversion without using
// any library function in Java
public class Main {static String UpperToLower(String s) {String result = "";
char ch = ' ';
for (int i = 0; i < s.length(); i++) {//check valid alphabet and it is in Uppercase
if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {ch = (char)(s.charAt(i) + 32);
}
//else keep the same alphabet or any character
else {ch = (char)(s.charAt(i));
}
result += ch; // concatenation, append c to result
}
return result;
}
public static void main(String[] args) {System.out.println(UpperToLower("IncludeHelp.com"));
System.out.println(UpperToLower("www.example.com"));
System.out.println(UpperToLower("[email protected]"));
System.out.println(UpperToLower("[email protected]"));
}
}

Output

输出量

includehelp.com
www.example.com
[email protected]
[email protected]

翻译自: https://www.includehelp.com/java-programs/uppercase-to-lowercase-conversion-without-using-any-library-function-in-java.aspx

java 大小写转换函数

java 大小写转换函数_不使用Java中的任何库函数将大写转换为小写相关推荐

  1. c大小写转换函数_字符处理——大小写转换编程思路扩展

    1.简单实现 前面我们实现了首字母大写.转换大写.转换小写3个功能,如果再实现一个大小写互换,有了前面的基础,实现起来应该没什么大问题: Function FUpperLowerSwap(str As ...

  2. java 动态调用函数_深入讲解Java语言中的函数动态调用方式

    相 信 有 不 少 人 使 用C 语 言 的 函 数 指 针 实 现 过 函 数 的 动 态 调 用. 适 当 地 运 用 函 数 动 态 调 用 功 能 不 仅 能 减 少 代 码 数 量, 而 且 ...

  3. mysql 如何把date转换数字_请教:mysql中,如何将date字段转换为int字段?

    你的位置: 问答吧 -> 数据库 -> 问题详情 请教:mysql中,如何将date字段转换为int字段? 刚开始设计数据库时候,没有想到date类型只能精确到某一天,不能精确到秒. 现在 ...

  4. java金额转换函数_将阿拉伯数字转换成人民币大写形式的JAVA工具类

    http://wallimn.iteye.com/admin/blogs/365769 public class MoneyUtil { private final static String[] C ...

  5. 用java实现combin函数_【算法-Java实现】组合总和

    [算法-Java实现]组合总和 一.问题描述: 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合.c ...

  6. java编写salary函数_编写一个Java程序,在程序中包含一个Employee类,Employee类包含name、age、salary三个成员变量...

    编写一个Java程序,在程序中包含一个Employee类,Employee类包含name.age.salary三个成员变量,Employee类中有4个构造方法,分别为无参的.带一个参数用来对name属 ...

  7. php 清除英文字母,PHP英文字母大小写转换函数小结

    PHP英文字母大小写转换函数小结 发布于 2015-01-23 10:54:41 | 143 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertext Pr ...

  8. php 英文小写变大写,PHP_PHP英文字母大小写转换函数小结,每个单词的首字母转换为大写 - phpStudy...

    PHP英文字母大小写转换函数小结 每个单词的首字母转换为大写:ucwords() $foo = 'hello world!'; $foo = ucwords($foo);             // ...

  9. php 英文小写变大写,PHP英文字母大小写转换函数

    例1,每个单词的首字母转换为大写:ucwords() 复制代码 代码示例: $foo = 'hello world!'; $foo = ucwords($foo);             // He ...

最新文章

  1. 【错误记录】Flutter 环境安装相关问题 ( 执行 flutter doctor 命令后续错误处理 )
  2. Java 设计模式——状态模式
  3. (转)【前端模板之路】一、重构的兄弟说:我才不想看你的代码!把HTML给我交出来!...
  4. KPI到底是个啥东东,如何设置KPI,我想你需要懂这些
  5. 服务器php只显示文本,服务器上的php echos文件是文本而不是二进制文件
  6. Java Byte类的hashCode()方法及示例
  7. 关于解决 从相册中选择照片后无法剪切图片以及无法加载图片的问题
  8. JSP ---- 入门
  9. console线驱动安装_低压灯带和高压灯带区别是啥 安装方法是啥?
  10. 猎豹网校C++ Primer学习笔记2
  11. 批量调度工具 Taskctl 作业类型的维护管理
  12. MATLAB 指定线型和颜色
  13. 计算机广告制作介绍,计算机广告制作.ppt
  14. 9个精品AI开源免费实战项目助你掌握AI工程师基本技能
  15. ContraD论文部分翻译与解读(Training GANs with Stronger Augmentations via Contrastive Discriminator)
  16. 计算年龄的sql语句
  17. 产品说明书应该如何制作?
  18. 基于RGB-D图像的视觉里程计连续尺度空间直接图像对齐 (ICRA 2021)
  19. 读后感《富爸爸穷爸爸》
  20. window.postMessage - 前端跨域通信

热门文章

  1. feko软件_计算电磁学各种方法和电磁仿真软件简述
  2. mysql百万数据根据索引查询_mysql创建多列索引查询百万表数据的性能优化经验分享...
  3. es 删除重复数据_怎么标识并删除SPSS数据库里的“重复个案”?
  4. python matplotlib 绘制曲线图,柱状图
  5. 第一章、第一节 Angular基础
  6. UVA1586 ​​​​​​​ Molar mass
  7. Orange Business Services 全球发布 Easy Go Network,帮助企业加速实现“网络即服务”...
  8. a20隐藏底部按钮及隐藏状态栏和虚拟按键栏
  9. 100c之23:两个平方数
  10. [赵星理]《简单男人》--歌曲温暖你的心,激励你前进