重写java.lang.String IndexOf()方法,实现对字符串以ASCII规则截取
/**
* 根据元数据和目标ascii位数截取字符串,失败返回-1
* @param sourceStr 元数据字符串
* @param endIndex 截取到第几位
* @return 结果字符串
*/
public static String indexOf(String sourceStr,int endIndex){
int length = ;
StringBuilder result = new StringBuilder();
List<String> resultList = new ArrayList<String>();
for(int i = ; i < sourceStr.length(); i++){
int ascii = Character.codePointAt(sourceStr,i);
if(ascii >= && ascii <=){
length++;
resultList.add(String.valueOf(ascii));
}else{
length+=;
resultList.add(String.valueOf(ascii));
}
if(length>){
if((length==sourceStr.length() && length <= endIndex) || length == endIndex || length == endIndex-){
for (String string : resultList) {
result.append(asciiToString(string));
}
return result.toString();
}
}
}
//return String.valueOf("-1");
/**
* 根据业务要求,如果传进来的参数为空值的时候默认返回空字符串
*/
return "";
} /**
* 将ascii码转换为utf-8
* @param value ascii编码 多个以,号分割
* @return 结果字符串
*/
public static String asciiToString(String value) {
StringBuffer sbu = new StringBuffer();
String[] chars = value.split(",");
for (int i = ; i < chars.length; i++) {
sbu.append((char) Integer.parseInt(chars[i]));
}
return sbu.toString();
}
重写java.lang.String IndexOf()方法,实现对字符串以ASCII规则截取的更多相关文章
- java.lang.String.indexOf()用法
java.lang.String.indexOf(char ch) 方法返回字符ch在指定字符串中第一次出现的下标索引位置 如果字符ch在指定的字符串中找不到,则返回-1 示例: import jav ...
- There is no getter for property named 'XXX' in 'class java.lang.String'解决方法
<select id="ProjectHomePage" parameterType="string" resultType="java.uti ...
- java.lang.String.regionMatches方法使用
regionMatches(boolean ignoreCase,int toffset,String other,int ooffset,int len): regionMatches(int to ...
- java.math.BigDecimal cannot be cast to java.lang.String解决方法
从mysql数据库里取decimal(18,2)封装到Map<String,String>中 BigDecimal b = new BigDecimal(resultMap.get(&qu ...
- java.lang.string split 以点分割字符串无法正常拆分字符串
//错误的做法String ip="192.168.11.23"; String[] spstr_IP=ip.split(".");//这种方式无法拆分在ip字 ...
- java.lang.String.getBytes(String charsetName)方法实例
java.lang.String.getBytes(String charsetName) 方法编码将此String使用指定的字符集的字节序列,并将结果存储到一个新的字节数组. 声明 以下是java. ...
- 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String
从数据库取出一个 Count函数 统计的值 在代码中要转成Integer类型的时候 Integer.parseInt((String)map.get("ID_")) 报了一下错误: ...
- mybatis之org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'time' in 'class java.lang.String'
mybatis接口 List<String> getUsedCate(String time); 配置文件 <select id="getUsedCate" pa ...
- java.lang.String 类的所有方法
java.lang.String 类的所有方法 方法摘要 char charAt(int index) 返回指定索引处的 char 值. int codePointAt(int index) 返回指定 ...
随机推荐
- js和jquery实现回到顶层
js <!DOCTYPE html> <html> <head> <title>返回顶部</title> <style> bod ...
- leetcode笔记:Majority Element
一. 题目描写叙述 Given an array of size n, find the majority element. The majority element is the element t ...
- ubuntu下打开eclipse·发现没有顶尖菜单项
在安装eclipse时,打开集成开发环境后没有菜单项. 网上些人说要写个shell脚步,感觉有点麻烦,其实就是少了一个环境变量 BUNTU_MENUPROXY. 在/etc/profile 里面新建这 ...
- HDU 5302(Connect the Graph- 构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 返回模式有流式(streaming)和整体(total) 热词词表解决方案
重要术语说明_语音识别(ASR)_智能语音交互-阿里云 https://help.aliyun.com/document_detail/72238.html 返回模式(response mode) ...
- 原创教程之——reactjs 组件入门教程
在学习react之前,希望你有以下准备: react的安装ECMAScript 6基础 本文不讲解react的安装步骤,若需了解请移步官方网站(https://reactjs.org/),那里讲解非常 ...
- POJ3177 Redundant Paths —— 边双联通分量 + 缩点
题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total ...
- c语言和oc对比
1)源文件对比 思考&实现1: 1)在C语言中,我们遇到不同后缀的文件有哪些? .c .o .out .h 2.基本语法对比 1)数据类型对比学习 2)变量的定义对比 3)流程控制语句对比 1 ...
- python库学习笔记——爬虫常用的BeautifulSoup的介绍
1. 开启Beautiful Soup 之旅 在这里先分享官方文档链接,不过内容是有些多,也不够条理,在此本文章做一下整理方便大家参考. 官方文档 2. 创建 Beautiful Soup 对象 首先 ...
- 【TJOI 2014】 上升子序列
[题目链接] 点击打开链接 [算法] 先考虑50分的做法 : f[i]表示以i结尾的本质不同的上升子序列的个数 则f[i] = sigma(f[j]) (j < i,a[j] < a[i] ...