招银中文字符前后加<>
来源:互联网 发布:stc52单片机引脚功能 编辑:程序博客网 时间:2024/06/07 03:05
public class Main { private String addSingal(String str) { if (str == null) { return null; } int n = str.length(); if (n == 1) { if (isLetter(str.charAt(0))) return str; return "<>" + str + "<>"; } String res = ""; boolean flag = false;//表示当前字符的前一个字符是否是中文,如果是中文则是true,如果是英文则是false char c; for (int i = 0; i < n; i++) { c = str.charAt(i); if (!isLetter(c)) { if (flag == false) { res = res + "<>" + c; flag = true; } else { res = res + c; flag = true; } } else { if (flag == true) { res = res + "<>" + c; flag = false; } else { res = res + c; flag = false; } } }//for if (!isLetter(str.charAt(n - 1))) return res + "<>";//最后一个字符是中文,末尾需要加<> return res; }//addSingal private boolean isLetter(char c) { if (c - 'a' >= 0 && c - 'z' <= 0) return true; return false; }//isLetter public static void main(String[] args) { System.out.println(new Main().addSingal("abc中国d美国"));//abc<>中国<>d<>美国<> System.out.println(new Main().addSingal("abc中国d美国e"));//abc<>中国<>d<>美国<>e System.out.println(new Main().addSingal("abc中国de"));//abc<>中国<>de System.out.println(new Main().addSingal("abc"));//abc System.out.println(new Main().addSingal("中"));//<>中<> }}
阅读全文
0 0
- 招银中文字符前后加<>
- 字符串编码--中文字符前后加<>
- 在文本段落的前后加字符
- 中文字符长度则加 3
- 数字前后加*号
- 前后台中文乱码
- 去除字符窜前后空格
- 字符串去除前后字符方式
- mysql 去除前后空白字符
- 前后台中文乱码问题
- 前后台中文乱码解决方案
- C++:函数名前后加const
- 函数名前后加const的区别
- C++中函数名前后加const
- android string.xml 前后加空格
- 中文字符
- 字符加解密
- perl去除字符串前后的字符
- QT5.9.1入门一:GUI的hello world
- Hibernate中缓存的问题
- 18:验证子串
- ActiveMQ引起的JDK1.7 SSL错误
- Leetcode练习 #11 Container With Most Water
- 招银中文字符前后加<>
- 【编译原理】第三章作业
- foreach与迭代器
- Oh Your Royal Greediness! UVA
- 第二周项目2 程序的多文件组织
- gensim学习之corpora.Dictionary
- 在IDEA中实战Git
- python概率计算
- HTML、CSS、JavaScript网页制作从入门到精通