ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 统计字节数 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 18:14:16 <br/> * * @param instr * 入参|输入字符串|{@link java.lang.String} * @param charset * 入参|编码方式(UTF-8或GBK)|{@link java.lang.String} * @param length * 出参|字节长度|{@link int} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "统计字节数", style = "处理型", type = "同步组件", comment = "字符串字节数", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 06:14:16") @InParams(param = { @Param(name = "instr", comment = "输入字符串", type = java.lang.String.class), @Param(name = "charset", comment = "编码方式(UTF-8或GBK)", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "length", comment = "字节长度", type = int.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_byteLength(String instr, String charset) { if (charset == null || !Charset.isSupported(charset)) { return ResultBase.newFailureResult("TPTS1006", "编码方式输入错误,charset=" + charset); } try { return ResultBase.newSuccessResult(instr == null ? 0 : instr .getBytes(charset).length); } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTS1007", "编码方式转换错误:" + AppLog.errorMsg(ex)); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/a0/22/a022f9812612b55b5c55aba4c119f206_1869x891.png) # 参数说明及示例 ## 入口参数 输入字符串:输入一串字符串,示例: `"qwertyuiop"` 编码方式(UTF-8或GBK):设置字符串的编码格式,示例: `"utf-8"` ## 出口参数 字节长度:返回指定编码集的字节长度,示例: `__INNER__["result"]`