找出字符串中连续的子字符
来源:互联网 发布:绕任意轴旋转矩阵 编辑:程序博客网 时间:2024/04/19 14:28
public class StringUtil {
public static String[] lxString(String str) {
char[] chars = str.toCharArray();
List<String> list = new ArrayList<String>();
for (int i = 0; i < chars.length - 1;) {
System.out.println(i);
int a = chars[i + 1] - chars[i];
StringBuffer sb = null;
if (a == 1) {
// 正序
sb = new StringBuffer();
sb.append(chars[i]);
sb.append(chars[i + 1]);
for (int j = i + 1; j < chars.length - 1; j++) {
int b = chars[j + 1] - chars[j];
if (b == 1) {
sb.append(chars[j + 1]);
i = j + 1;
} else {
i++;
break;
}
}
list.add(sb.toString());
} else {
i++;
}
}
String[] strs = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
strs[i] = list.get(i);
}
return strs;
}
public static void main(String[] args) {
String[] strs = StringUtil.lxString("abcd1134456");
for (String string : strs) {
System.out.println(string);
}
}
}
public static String[] lxString(String str) {
char[] chars = str.toCharArray();
List<String> list = new ArrayList<String>();
for (int i = 0; i < chars.length - 1;) {
System.out.println(i);
int a = chars[i + 1] - chars[i];
StringBuffer sb = null;
if (a == 1) {
// 正序
sb = new StringBuffer();
sb.append(chars[i]);
sb.append(chars[i + 1]);
for (int j = i + 1; j < chars.length - 1; j++) {
int b = chars[j + 1] - chars[j];
if (b == 1) {
sb.append(chars[j + 1]);
i = j + 1;
} else {
i++;
break;
}
}
list.add(sb.toString());
} else {
i++;
}
}
String[] strs = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
strs[i] = list.get(i);
}
return strs;
}
public static void main(String[] args) {
String[] strs = StringUtil.lxString("abcd1134456");
for (String string : strs) {
System.out.println(string);
}
}
}
阅读全文
0 0
- 找出字符串中连续的子字符
- 从字符串S中找出不包含重复字符的最大连续子字符串长度
- 找出字符串中连续出现次数最多的子串
- 找出字符串中连续出现次数最多的子串
- 找出字符串中连续出现次数最多的子串
- 找出一个字符串中最长的连续数字子串,输出该字符串及长度
- 找出一个字符串中最长连续相同子串
- 字符串中找出连续最长的数字子串,并返回这个数字串的长度
- 【面试题】找出字符串中连续出现次数最多的子串
- [百度面试题]找出字符串中连续出现次数最多的子串
- 【C++】在字符串中找出连续最长的数字子串
- 小菜鸟请求各位大大帮忙在一个字符数组中,找出最长连续重复的字符子序列
- 从字符串中找出一个最长的不含重复字符的子字符串
- 请找出两个字符串顺序连续的字符。
- 找出一个字符串中不含重复字符的最长子字符串
- 找出一个字符串中出现的重复的最长的字符子串
- 找出字符串中最长的一段没有重复字符的子串
- 【c++】字符串中找出最长的连续数字字符串
- CF384E Propagating tree(线段树+思路题)
- 拿到一块开发板应该怎样才能尽快着手
- Android中为Button注册监听器最常用的两种方法
- 人工智能的深渊
- Ajax 省市区三级联动数据库(数据库代码)
- 找出字符串中连续的子字符
- 网络协议相关问题(一)
- 【JavaWeb】Hibernate Dao层设计
- poj1061-exgcd
- iOS中的谓词(NSPredicate)使用
- 对象导航查询和OID查询(补)
- 【算法】The Skyline Problem
- js浮点数精度问题
- Java消息机制 ActiveMQ入门实例